I have a master form with a listbox and a subform. The listbox is unbound. The form has a recordsource of peoples data. Each row of the listbox contains a unique TelefID (Autonumber), name, telephone etc of each person. The subform is on the master form and contains detailed data about every person including TelefID. Thus when the user selects a person from the list box the subform should display the details of that person. I have defined a query to select the person from the listbox and link it to the right detail record. The code is below:
There is something wrong with the query. It asks for the value of the parameters as if the value J1 does not exist. Help please.
Code:
Dim QryName As String
Dim qdf As DAO.QueryDef
Dim J1 As Long
ParName = "ListNumbersFm"
ForName = "EnterRecordFmSub"
QryName = "SelQy"
J1 = Nz(Me.People, 1)
RowSource = "SELECT * from TelephoneAAA " & _
" WHERE " & _
"[Forms]![ListNumbersFm].[EnterRecordFmSub].[Form].TelefID = " & J1 & ";"
SQLStatement = RowSource
If QueryExists(QryName) = True Then CurrentDb.QueryDefs.Delete (QryName)
Set qdf = CurrentDb.CreateQueryDef(QryName, SQLStatement)
With Forms!ListNumbersFm!EnterRecordFmSub
.SourceObject = "Query." & QryName
.LinkMasterFields = "TelefID"
.LinkChildFields = "TelefID"
.Requery
End With
There is something wrong with the query. It asks for the value of the parameters as if the value J1 does not exist. Help please.