match CustomerID from one form to another

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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) 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!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This solution ok?

If its not ok, you need to give feedback so we can help you better
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.