We help IT Professionals succeed at work.

match CustomerID from one form to another

Medium Priority
Last Modified: 2013-11-26
I have two forms in vb 6.
Both have the basic data from the recordset. The second form groups the customers by lastname, firstname on a listbox. There are also textboxes on the second form which shows the CustomerID which is the unique identifier.

What I want to do is to be able to click a button or on the name in the listbox and have that record on form 1 ( ie customers.form) to move the recordset to the correct customer so they match.

The code for the listbox on form 2 is posted
Is there a way to click on the name in the listbox and force the recordset in form 1 to match? They would need to match with the CustomerID as that is the primary key and the unique identifier, although the user does not see the customerID.
Private Sub lstContacts_Click()
    'Update Contact Detail data (replace null values with empty strings to prevent errors)
    With rsContacts
  .Filter = "CustomerID='" & aContactIDs(lstContacts.ListIndex) & "'"
        txtTitle.Text = myNZ(!Title, "")
        txtFirstName.Text = myNZ(!firstname, "")
        txtLastName.Text = myNZ(!lastName, "")
        txtAddress.Text = myNZ(!Address, "")
        txtCity.Text = myNZ(!City, "")
        txtState.Text = myNZ(!State, "")
        txtZIP.Text = myNZ(!ZIP, "")
        txtPhone.Text = myNZ(!Phone, "")
        txtCell.Text = myNZ(!Cell, "")
        txtCustomerID.Text = myNZ(!Customerid, "")
    End With
End Sub

Open in new window

Watch Question


If Form2 and Form 1 are both visible and usable (none of them is modal):

You should be able to modify the other form (form1), provided that form2 is not being shown modally.
You need to have a public recordset variable in form1 (defined as Public rsMyData as adodb.recordset), and already have an instance of it created (in the Load event of form1, put: Set rsMyData=new adodb.recordset). Of course, you may already have all of this defined and working, just wanted to let you know that it should be public.

Anyways, once you have it, put this:

Form1.MyData.Filter = "CustomerID='" &cstr( !customerID)

in the line 17 of the snippet you submitted.

If Form2 is shown modally (called from Form1):

If Form2 is shown modally, then you need to save the customerID in a global variable, and check its value when the control returns to form1, so you can update the filter property. Something like this:

In Form1 :

'... some code blah blah
MyGlobalVar=  'set the global var to an invalid value (zero)
form2.show vbmodal, me 'show the form2 modally
if MyGlobalVar <> 0 then 'CustomerID should not be zero unless form2 was cancelled without action
    rsMyData.filter="CustomerID='" &cstr( MyGlobalVar) 'filter the rs
end if
'... some more code blah blah

And in Form2, place this in the 17th line of the script you just submitted:

MyGlobalVar= !customerID

and this in the "cancel" button, or similar:


Well, I hope this helps. I think this is what you asked, but in case I misunderstood something(I'm not a native english speaker), then sorry.

Greetings from Argentina!


This solution ok?

If its not ok, you need to give feedback so we can help you better

Explore More ContentExplore courses, solutions, and other research materials related to this topic.