troubleshooting Question

Reference between forms in VBA Code

Avatar of maximyshka
maximyshka asked on
Microsoft AccessOffice ProductivityMicrosoft Office
10 Comments2 Solutions664 ViewsLast Modified:

Would you please tell me what's wrong with VBA Code.  Purpose of the code: by using datasheet from db1, by clicking on the field "account number" field I should go to to the same account number on continuous form which is located in DB2.

Complications: please see the data in the form2 of the db2 (Source: table 2)

The below listed VBA should be put to onclick event of the "Account Number" field from the form 1.

Private Sub Account_No_Click()
Dim strLinkCriteria
Dim objAccess As Access.Application
Set objAccess = New Access.Application
objAccess.Visible = True
objAccess.OpenCurrentDatabase ("C:\Users\Desktop\db2")
strLinkCriteria = "[Account No]= & Chr(39) & Forms![Form2]!txtAccountNum"
objAccess.DoCmd.OpenForm "db2", acNormal, wherecondition = strLinkCriteria
End Sub

Open in new window

Please validate the code, you may want to adjust link in DB1 vba code
Graham Mandeno

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros