D
DavidG
Hi All,
I know this question has been asked before but i havent been able to find an
appropriate solution as yet. Ill start by defining my setup.
I currently have two tables where my data is stored, "Customers" and
"Contacts" with "Customer ID" being the primary key for "Customers". The
Customers table stores contact details for company i.e. delivery adress,
website, and the Contacts table contains data for employees of that company.
They are linked via the "Customer ID" key.
My form is set up with "Customers" details being displayed in the header of
my main form and the "Contacts" details as a subform in the Details section
of my main form.
I would like to be able to search for a "Name" from my subform which would
subsequently bring up the details for the "Customer" and the rest of the
"Contacts" relating to that Customer ID. Here is the code i am using at the
moment. It is a modified version of a previous solution that was trying to
accomplish a similar task to mine:
Private Sub Search_AfterUpdate()
Dim strWhere As String
Dim varResult As Variant
Dim rs As DAO.Recordset
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.Search) Then
strWhere = "customer_ID = """ & Me.Search & """"
Debug.Print strWhere
varResult = DLookup("Customer_ID", "Contacts1", strWhere)
If IsNull(varResult) Then
MsgBox "Not found"
Else
With Me.RecordsetClone
strWhere = "Name = """ & varResult & """"
Debug.Print strWhere
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found. Filtered?"
Else
Me.Bookmark = rs.Bookmark
End If
End With
End If
End If
End Sub
I keep getting "Run-time error '2001': You canceled the previous operation.
It points me to this line when i de-bug:
varResult = DLookup("Customer_ID", "Contacts1", strWhere)
Is this something to do with the Where function?
I hope someone will be able to help me as i am really stuck with this.
Thanks in Advance,
Dave.
I know this question has been asked before but i havent been able to find an
appropriate solution as yet. Ill start by defining my setup.
I currently have two tables where my data is stored, "Customers" and
"Contacts" with "Customer ID" being the primary key for "Customers". The
Customers table stores contact details for company i.e. delivery adress,
website, and the Contacts table contains data for employees of that company.
They are linked via the "Customer ID" key.
My form is set up with "Customers" details being displayed in the header of
my main form and the "Contacts" details as a subform in the Details section
of my main form.
I would like to be able to search for a "Name" from my subform which would
subsequently bring up the details for the "Customer" and the rest of the
"Contacts" relating to that Customer ID. Here is the code i am using at the
moment. It is a modified version of a previous solution that was trying to
accomplish a similar task to mine:
Private Sub Search_AfterUpdate()
Dim strWhere As String
Dim varResult As Variant
Dim rs As DAO.Recordset
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.Search) Then
strWhere = "customer_ID = """ & Me.Search & """"
Debug.Print strWhere
varResult = DLookup("Customer_ID", "Contacts1", strWhere)
If IsNull(varResult) Then
MsgBox "Not found"
Else
With Me.RecordsetClone
strWhere = "Name = """ & varResult & """"
Debug.Print strWhere
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found. Filtered?"
Else
Me.Bookmark = rs.Bookmark
End If
End With
End If
End If
End Sub
I keep getting "Run-time error '2001': You canceled the previous operation.
It points me to this line when i de-bug:
varResult = DLookup("Customer_ID", "Contacts1", strWhere)
Is this something to do with the Where function?
I hope someone will be able to help me as i am really stuck with this.
Thanks in Advance,
Dave.