troubleshooting Question

Variables for form names in VBA

Avatar of ChadLittle
ChadLittle asked on
Microsoft Access
18 Comments2 Solutions434 ViewsLast Modified:
Hi,

I have a sub that works for one button, but I am trying to share it for multiple buttons on a form, each of which would write things on a different form than the other buttons.  To accomplish this, I need to put variables in two places to finish, but I can't figure it out.  My problem is in lines 17 and 19 below.  Here is part of the code I am using:
strSubFormName As String
Dim strFormAddress as String

Private Sub cmdCreatePO_Click()

strSubFormName = ("Form_fsubPOLines")

strFormAddress = ("Forms!frmPO.fraPOLines.Form")

Call CreatePO

End Sub


Private Sub CreatePO

Dim frmLines as strSubFormName 'How do I do this as a variable?  Dim frmLines as Form_fsubPOLines works.

Set frmLines = strFormAddress 'How do I do this as a variable?  Set frmLines = Forms!frmPO.fraPOLines.Form works.

Do Until rsSourceLines.EOF
	frmLines.Recordset.AddNew
        frmLines.cboSOLinesID = rsSourceLines!SOLinesID
        frmLines.lngUnitQuantity = rsSourceLines!lngSelectedQuantity
        frmLines.UnitsID = rsSourceLines!UnitsID
        frmLines.cboSOLinesID_AfterUpdate
        frmLines.Dirty = False
        rsSourceLines.MoveNext
Loop

End Sub
Do you know how I can rewrite lines 17 and 19 to work?

Thank you!
Chad
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 18 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 18 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