Passing Arguments to a New Form

J

Joe Jeffcoat

Hello All...

I have a form that will allow a user enter information with one of the
fields being a date. I have a button beside this date field that will open
a new form that has a calendar on it. The purpose of this new form will
allow the user to browse the calendar, click on a date, click an "ok"
button, then be returned to the previous form with that date field populated
with the selected date from the calendar. I have been able to successfully
pass the form name to the form being opened (docmd.OpenForm
"frmCalendar",acNormal,,,,Me.Name or something close). Now I'm stuck... I'm
not sure where to go from here. How do I link back to the form that opened
the calendar form? Better yet... how do I link back to the field on the
form that opened the calendar form?

I'm wanting to do this so that I can have a "generic" calendar form that all
I have to do is provide an argument and it will send back the information.
This way, I don't clutter my database with copies of a form that have to
interact with different forms.

If you could help, I would greatly appreciate it. If I've confused you
more, reply back and I'll try to explain better.

Thanks!
Joe
 
C

Cameron Sutherland

I made that exact thing and here is what I do:

1. Make your calendar form with 2 hidden fields called
txtFieldName & txtFormName
2. Make a function that your forms throughout your
application will call. This function module will open the
calendar form and pass it the form object and the name of
its field where the calendar's value should go:

Function OpenCalendar(TargetForm As String, TargetControl
As String)
'*********************************************************
'* This module takes the two variables passed in and
'* sends them to the Calendar form.
'*
'* August, 2001
'* Created by Cameron Sutherland
'*
'* Syntax in a form:
'* Call OpenCalendar(Me.Name, "FeildName")
'*
'*********************************************************
DoCmd.OpenForm "frmCalendar", acNormal, "", "", ,
acNormal
With Forms![frmCalendar]
![txtFormName] = TargetForm
![txtFieldName] = TargetControl
End With
End Function

3. On your close event of the calendar form (OK button in
this example) you can format the user's date to look the
way you want and send it back to the form that called it:
Private Sub cmdOK_Click()
Forms(txtFormName)(txtFieldName) = Format
(txtDate, "Medium date") 'Output choosen date
DoCmd.Close
End Sub

If you get stuck email me and I can send you my calendar.

-Cameron Sutherland
 
M

MikeB

Joe,
I have a sample db that has a calendar form and will return a value to textbox on doubleclick or
command button. The code is commented and has an accompanying readme file to tell you how to start
it. Works in datasheet view as well. www.byerley.net/AccessCalDemo.zip

The db is AC2K.
 
J

Joe Jeffcoat

Thanks for the help...
Building that function was pretty easy... Great Idea! Thanks Cameron.

Mike, I also downloaded your sample db. It has some good ideas in it as
well, that I may incorporate into my db.

Thanks again for the responses and the help!
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top