P
PennyB
I have a combo box that I used the wizard to create to show multiple columns.
The stored value is going into my contacts table FirmName. Now, since I
used the wizard the code below was written to find the first record it could
find; however that is assuming that my FirmName is unique, which it is not.
I created a query to use for the combo box called qryContactsUnique which are
unique records, but the firm name can show up several times as there are many
contacts at one firm. So the code below works to fill in my form; however,
it finds the first record and not the entire record the user clicks on. Can
you please help me change the code so that the correct contact information is
loaded into the form?
Private Sub cboFirmName_AfterUpdate()
Const cQUOTE = """"
Dim strCriteria As String
Dim rstDevs As DAO.Recordset
Set rstDevs = CurrentDb.OpenRecordset("Select * from tblContacts order by
[FirmName] Desc;")
strCriteria = "[FirmName] = " & cQUOTE & cboFirmName & cQUOTE
rstDevs.FindFirst strCriteria
If Not rstDevs.NoMatch Then
With Me
.[First] = rstDevs![First]
.[Last] = rstDevs![Last]
.[Address] = rstDevs![Address]
.[City] = rstDevs![City]
.[State] = rstDevs![State]
.[Zip] = rstDevs![Zip]
.[Phone] = rstDevs![Phone]
.[Fax] = rstDevs![Fax]
. = rstDevs![Email]
.[LicenseType] = rstDevs![LicenseType]
.[LicenseNumber] = rstDevs![LicenseNumber]
.[ExpirationDate] = rstDevs![ExpirationDate]
.[WorkersCompProvider] = rstDevs![WorkersCompProvider]
.[WorkersCompPolicy] = rstDevs![WorkersCompPolicy]
.[WCExpirationDate] = rstDevs![WCExpirationDate]
End With
rstDevs.Close
Set rstDevs = Nothing
End If
End Sub
The stored value is going into my contacts table FirmName. Now, since I
used the wizard the code below was written to find the first record it could
find; however that is assuming that my FirmName is unique, which it is not.
I created a query to use for the combo box called qryContactsUnique which are
unique records, but the firm name can show up several times as there are many
contacts at one firm. So the code below works to fill in my form; however,
it finds the first record and not the entire record the user clicks on. Can
you please help me change the code so that the correct contact information is
loaded into the form?
Private Sub cboFirmName_AfterUpdate()
Const cQUOTE = """"
Dim strCriteria As String
Dim rstDevs As DAO.Recordset
Set rstDevs = CurrentDb.OpenRecordset("Select * from tblContacts order by
[FirmName] Desc;")
strCriteria = "[FirmName] = " & cQUOTE & cboFirmName & cQUOTE
rstDevs.FindFirst strCriteria
If Not rstDevs.NoMatch Then
With Me
.[First] = rstDevs![First]
.[Last] = rstDevs![Last]
.[Address] = rstDevs![Address]
.[City] = rstDevs![City]
.[State] = rstDevs![State]
.[Zip] = rstDevs![Zip]
.[Phone] = rstDevs![Phone]
.[Fax] = rstDevs![Fax]
. = rstDevs![Email]
.[LicenseType] = rstDevs![LicenseType]
.[LicenseNumber] = rstDevs![LicenseNumber]
.[ExpirationDate] = rstDevs![ExpirationDate]
.[WorkersCompProvider] = rstDevs![WorkersCompProvider]
.[WorkersCompPolicy] = rstDevs![WorkersCompPolicy]
.[WCExpirationDate] = rstDevs![WCExpirationDate]
End With
rstDevs.Close
Set rstDevs = Nothing
End If
End Sub