troubleshooting Question

Reference between forms in VBA Code

Avatar of maximyshka
maximyshka asked on
Microsoft OfficeMicrosoft AccessOffice Productivity
10 Comments1 Solution664 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

Please validate the code, you may want to adjust link in DB1 vba code
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
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 1 Answer 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