By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Passing a variable to a form name AND a control name??

P: n/a
I have a single form that I want to make as generic as possible. The
form contains a Calendar control.

Using OpenArgs I pass values from the form that's calling the calendar,
and the field the calendar should write to. I do this so I can use the
same calendar form throughout my database.

Does anyone know how to pass this info back to the form that called it?
I'm trying to set the value of the control on a form using a Submit
button on the calendar form. My code looks like this:

Private Sub Submit_Click()
On Error Resume Next
Dim strForm, strField As String
strFormName = Left(Me.OpenArgs, InStr(Me.OpenArgs, "|") - 1)
strFieldName = Mid(Me.OpenArgs, InStr(Me.OpenArgs, "|") + 1)
X = "Forms! " & strFormName & "." & strFieldName & ".Value =
Me.Calendar0.Value"

DoCmd.Close
End Sub

When I break it, the variable X has the proper syntax I need but
there's no way to run X. I need to figure out how to set
Forms! (strFormName) . (strFieldName) .Value = Me.Calendar0.Value

Anyone know if it can be done?

Apr 26 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
There's an example of this in Access Developer's Handbook... no nasty
ActiveX muck to deal with, either.

The way you get the data into the form in question is to cause a
control on the form you wish to enter data into call a function that
opens the calendar. Then the calendar passes a value to the function,
which passes it to your form.

IIRC, ADH's code does something like this:
1. opens the Calendar form
2. waits for the user to select a value (ie does nothing)
3. when the user closes the calendar, the date selected gets passed to
a function's return value.
4. the value of the function is passed to the control in question.

IOW, someone has already done this, and quite well. Unless you're into
reinventing the wheel, get a copy of the book.

in a nutshell, I'd use the ADH version. It works well, and you spend
zero time/money developing your own solution.

I know that doesn't directly answer your question, and sounds like a
blatant sales pitch to boot. But I don't think any serious Access
developer should be without it. If you don't believe me, read the
reviews for yourself at Amazon. The only caveat to the book is that if
you don't understand VB, you won't understand most of the book. It's
definitely a beginner book (and they say that in the
Foreword/Introduction).

Apr 26 '06 #2

P: n/a
Nevermind, I got it. I had to set up a variable as type Form.

Apr 26 '06 #3

P: n/a
Here's what I came up with:

Private Sub Submit_Click()
On Error Resume Next

Dim strFormName, strFieldName As String
Dim Frm As Form
Dim Ctl As TextBox

strFormName = Left(Me.OpenArgs, InStr(Me.OpenArgs, "|") - 1)
strFieldName = Mid(Me.OpenArgs, InStr(Me.OpenArgs, "|") + 1)
Set Frm = Forms(strFormName)
Set Ctl = Frm.Controls(strFieldName)
Ctl = Me.Calendar0.Value
DoCmd.Close
End Sub

HTH,
Jana

Apr 26 '06 #4

P: n/a
ma********@gmail.com wrote in
news:11**********************@i39g2000cwa.googlegr oups.com:
I have a single form that I want to make as generic as
possible. The form contains a Calendar control.

Does anyone know how to pass this info back to the form that
called it?
I'm trying to set the value of the control on a form using a
Submit
button on the calendar form. Anyone know if it can be done?

download the datepicker discussed on this page and study the way
Brendan Kidwell did it. Or just borrow his form and code.

http://www.mvps.org/access/forms/frm0057.htm
--
Bob Quintal

PA is y I've altered my email address.
Apr 26 '06 #5

ADezii
Expert 5K+
P: 8,616
I have a single form that I want to make as generic as possible. The
form contains a Calendar control.

Using OpenArgs I pass values from the form that's calling the calendar,
and the field the calendar should write to. I do this so I can use the
same calendar form throughout my database.

Does anyone know how to pass this info back to the form that called it?
I'm trying to set the value of the control on a form using a Submit
button on the calendar form. My code looks like this:

Private Sub Submit_Click()
On Error Resume Next
Dim strForm, strField As String
strFormName = Left(Me.OpenArgs, InStr(Me.OpenArgs, "|") - 1)
strFieldName = Mid(Me.OpenArgs, InStr(Me.OpenArgs, "|") + 1)
X = "Forms! " & strFormName & "." & strFieldName & ".Value =
Me.Calendar0.Value"

DoCmd.Close
End Sub

When I break it, the variable X has the proper syntax I need but
there's no way to run X. I need to figure out how to set
Forms! (strFormName) . (strFieldName) .Value = Me.Calendar0.Value

Anyone know if it can be done?
This is a drastic alternative to your approach, but give it a try and see what you think:

'Declare a Public variable of type Control
Public ctlMyControl As Control

'In the calling Form explicitly initiate it and list the calling Form and field
'which will contain the return value. The only change you'll make.

Private Sub Form_Open(Cancel As Integer)
Set ctlMyControl = Forms![frmTest]![txtCalendarValue]
End Sub

'Your new Submit Button code
Private Sub Submit_Click()
On Error Resume Next
ctlMyControl.Value = Me![Calendar1].Value
Set ctlMyControl = Nothing
DoCmd.Close
End Sub
Apr 27 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.