G
Guest
I have a form called Company (Built off the Company table which contains a
list of all the vendors that we deal with). This includes a subform that
lists our Contacts at the Company. The sub form is based off a Contact table.
The subform lists Contact Name, Email and Phone number. The email and phone
number fields are disabled. The intent is that the user will select the
Contact Name which will automatically populate the email and phone number for
the selected Contact.
I have tried to accomplish this using the following code against the
AfterUpdate event of the Contact Name field. However, on running it I get a
"The Data Type Mismatch in Criteria Expression." error. Aargh!!! Any
suggestions?
Private Sub Contact_Name_AfterUpdate()
Dim rst As New ADODB.Recordset
Dim SQLstmt As String
SQLstmt = "SELECT * FROM [Contact] WHERE [ID] = """ & Me.Contact_Name & """"
rst.Open SQLstmt, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
With Me
.Email= rst!Email
.Phone_Number = rst!Phone_Number
End With
rst.Close
Set rst = Nothing
End Sub
list of all the vendors that we deal with). This includes a subform that
lists our Contacts at the Company. The sub form is based off a Contact table.
The subform lists Contact Name, Email and Phone number. The email and phone
number fields are disabled. The intent is that the user will select the
Contact Name which will automatically populate the email and phone number for
the selected Contact.
I have tried to accomplish this using the following code against the
AfterUpdate event of the Contact Name field. However, on running it I get a
"The Data Type Mismatch in Criteria Expression." error. Aargh!!! Any
suggestions?
Private Sub Contact_Name_AfterUpdate()
Dim rst As New ADODB.Recordset
Dim SQLstmt As String
SQLstmt = "SELECT * FROM [Contact] WHERE [ID] = """ & Me.Contact_Name & """"
rst.Open SQLstmt, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
With Me
.Email= rst!Email
.Phone_Number = rst!Phone_Number
End With
rst.Close
Set rst = Nothing
End Sub