Reference control on another form using variable

oihjk

Registered User.
Local time
Yesterday, 19:05
Joined
Feb 13, 2003
Messages
51
I have frmCalendar form that opens when I click a picture on frmMembers. I pass the name of the form that opened the frmCalendars form to a textbox on frmCalendars. Now what I'm wanting to do is when I select a certain date it puts the name of the text from txtFormName into a variable and then I can put the date selected into a field in the form that opened the Calendar. This is the code I have now.

Code:
Private Sub frmCal_Click()
Dim stDocName As String
stDocName = Me.txtFormName 'holds the form name that opened calendar
    
Forms!stDocName!DOB = [frmCal].Value 
DoCmd.Close acForm, "frmCalendar"

End Sub

When I try this, it says it can't find the form named stDocName. I tried this just to make sure it was getting the right info: MsgBox stDocName - It showed frmMembers, so it is getting the right info. If you have any ideas let me know.

Eric
 
A variable won't work in that situation. This is what I do:

Private Sub frmCal_Click()

If Not IsNull(Me.OpenArgs) Then
Select Case Me.OpenArgs
Case "Form1"
[Forms]![Form1]![Date1] = Me.frmCal.Value
DoCmd.Close acForm, "frmCalendar"
Case "Form2"
.....rest of code...

Pass the form name in the OpenArgs argument...

hth,
Jack
 
Have you tried... stDocName ="Forms!" & Trim(stDocName) & ".DOB"
I think that's right.

If that doesn't work to test stDocName, try the following...
1.)drop another textbox on your form(txtTextbox)
2.)in the code put b/4 the code that gives you the error... Me.txtTextbox=stDocName
3.)run the code and quit on the error
4.)look at the value in the txtTextbox to see what it is
5.)Adjust your stDocName variable accordingly
6.)Try running it again
7.)When it works, delete the txtTextbox from your form

If you know how to set breakpoints...
1.)Declare another string(i.e.strTest)
2.)strTest = "Forms!"& Trim(stDocName) &".DOB"
3.)set a breakpoint on that line in the code(click the left side of the code window next to that line>>it turns red w/ a dot)
4.)launch the code(it should stop at that line)
5.)press F8 to step through the code line by line
6.)set your mouse over strTest for a few seconds(the value should pop up like a"ControlTip" and allow you to see what strTest's value is.
7.)Adjust the strTest and repeat the preceding steps until it resembles the actual control you wish to reference.
8.)Copy the right side of strTest equation to the stDocName
9.)Remove the breakpoint(click the left side of the code window again)
 
Thanks for the replies

Jack I thought of trying that if I couldn't get the variable method to work. Thanks

Casey I'll give it a swing when I get a chance. I'll let you guys know what I come up with.

Thanks
Eric
 

Users who are viewing this thread

Back
Top Bottom