Whether or not you really need a query depends on what you want to put into
the controls. Regardless of the method you use to load data into the
controls, your code should be in the After Update of the even where the user
enters the value used to determine what to assign to the other controls. To
use a query requires establishing a recordset and reading the data from the
query fields and assigning the field values to the other controls. For
example:
Dim qdfLookUp As QueryDef
Dim rstLookUp as Recordset
Set qdfLookUp = dbs.QueryDefs("MYQueryName")
qdfLookup.Parameters(0) = Me.FirstControl
Set rstLookup = qdfLookup.OpenRecordset(dbOpenSnapshot, dbReadOnly)
If rstLookup.RecordCount = 0 Then
MsgBox "No Matching Data"
Else
Me.SecondControl = rstLookup![Field1]
Me.LastControl = rstLookup![Field2]
End If
set rstLookup = Nothing
set qdfLookup = Nothing
Sometimes, it is easier to use the DLookup function to accomplisth the same
thing:
Me.SecondControl = DLookup("[Field1]", "TableNameHere", "[FieldToMatch] =
'" & Me.FirstControl & "'")
Candace said:
Sorry about that. I need to have these two controls to auto-fill when a
certain value is placed in another control on the form. When I looked in
help on Access it said to create a query(whichI did) but it did not say how
to connect that query to the form so I'm stuck