Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Access Subforms in VB

WilkoWilko Member Posts: 8
[b][red]This message was edited by Wilko at 2006-2-8 3:10:8[/red][/b][hr]
Hi Guys,

I currently have a subform which relates to the primary key of the main form.

This subform contains possible 'Answers' which related back the main form/table 'Question'. Each possible answer has a true of false field to show whether or not it is the correct possible answer from the question field.

Currently the subform performs correctly, in that it shows up the 3 possible answers for each question... (in continuous form view)ie all three appear at once in 'form view' - but in the subform the only one answer and one true or false attribute appear at once.

Here is where the problem is - i need to be able to access the individual field values for these 3possible answers (in VB code). I cant work out how to do this? Does anyone know how access calls them? What will the checkboxname be? The problem is because there is only one checkbox on the form in 'Design View' (to see if the answer is the correct one), but then 3 in 'Form View', I cant work out how access distinguishes between them.

Many thanks

Ross




Comments

  • dokken2dokken2 Member Posts: 532
    : [b][red]This message was edited by Wilko at 2006-2-8 3:10:8[/red][/b][hr]
    : Hi Guys,
    :
    : I currently have a subform which relates to the primary key of the main form.
    :
    : This subform contains possible 'Answers' which related back the main form/table 'Question'. Each possible answer has a true of false field to show whether or not it is the correct possible answer from the question field.
    :
    : Currently the subform performs correctly, in that it shows up the 3 possible answers for each question... (in continuous form view)ie all three appear at once in 'form view' - but in the subform the only one answer and one true or false attribute appear at once.
    :
    : Here is where the problem is - i need to be able to access the individual field values for these 3possible answers (in VB code). I cant work out how to do this? Does anyone know how access calls them? What will the checkboxname be? The problem is because there is only one checkbox on the form in 'Design View' (to see if the answer is the correct one), but then 3 in 'Form View', I cant work out how access distinguishes between them.
    :
    : Many thanks
    :
    : Ross
    :
    :
    :
    :
    :
    You are correct, the problem the form displays *multiple* instances of records, while the form design itself has one control.

    If you refer to a control,
    MsgBox Forms.formMAIN.formSUB.Form!address.Value
    depending on *which* record in the subform has focus will determine which record value is displayed.

    One way to solve this is to use the primary/foreign key from your form to enumerate or filter the records in the table. You could use DAO or ADO. here's a DAO example-

    Dim db As DAO.Database, rs As DAO.Recordset
    Dim sql As String, MyKey As String

    'primary/foreign key [quotes for string]
    MyKey = Chr(34) & Me.LastName & Chr(34)
    'restrict sql-statement w/ WHERE clause
    sql = "SELECT * FROM Tbl2 WHERE (LastName=" & MyKey & ");"

    'open db with a sql-statement
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

    'loop thru records
    Do While Not rs.EOF
    MsgBox rs!LastName & "-" & rs!Address
    rs.MoveNext
    Loop

    'release resouces
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing

  • WilkoWilko Member Posts: 8
    Many thanks for that reply. I am going to investigate further into your information this afternoon, it looks like it will be a great help, regards

    Ross
Sign In or Register to comment.