Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values between modules

Status
Not open for further replies.

Carthesis

Technical User
Oct 29, 2002
100
GB
Quick explanation:

I have a number of different forms with date fields. I've got a popup form that has an Office 11 OCX Calendar on it. I'd like to use one pop-up form for all date entries instead of having to put an OCX object on every form.

So, steps are:

1) Open data form (frmData)
2) When you get to the date field (txtDateField), click a toggle button to show calendar
3) Calendar appears in a pop-up form (popCalendar), instead of being on the same form with it's visibility set to false
4) Click relevant value on calendar
5) Calendar form closes and populates field on original form { (frmData)!(txtDateField).Value = Value from (popCalendar) }

It all works as far as step 4), but 5) is where it all falls down. I'm just a bit stuck about how to get the information BACK to the form in question. I've tried to set the originator textbox by doing:

Dim Originator As TextBox
Set Originator = Forms![frmWithDateField]![txtDateField]

but this doesn't help, as the value is in the 'wrong' form code.

Can anyone help me out?
 
You may use the OpenArgs named parameter of the DoCmd.OpenForm method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
docmd.OpenForm "calpopup",,,,,acDialog

me.datefield = forms!calpopup!popCalendar
docmd.close acform, "calpopup",acSaveNo


on the calpopup form have a close button

with this code

me.Visible=false
 
So I'd be having something like the following in the OnClick() event of the 'Display calendar' button?

Dim Originator As TextBox
Set Originator = Forms![frmWithDateField]![txtDateField]

DoCmd.OpenForm "popCalendar", , , , acFormEdit, , Originator

Then I could refer to Me.OpenArgs in the code for the Calendar form, ie:

Me.OpenArgs.Value = ocxCalendar.Value

I'm not at work at the moment, so I can't try it, but if someone could give me a heads up as to if I'm on the right lines, that'd be awesome.

Thanks.

 
Then I could refer to Me.OpenArgs in the code for the Calendar form, ie:
Me.OpenArgs.Value = ocxCalendar.Value
No that would not work for several reasons.

Use pwise's technique. Here are some comments showing how it works.

docmd.OpenForm "calpopup",,,,,acDialog
' Pops open the calendar form
' code execution stops on the calling form
'
' As stated add a close button that hides the calendar
' on the calendar form 'me.visible = false
'
' Code execution resumes on calling form
' set the value of the date field equal to the value of the
' calendar
me.datefield = forms!calpopup!popCalendar
' close hidden form
docmd.close acform, "calpopup",acSaveNo


On the calendar form you could also add a cancel button. That button would close the form and not hide it. Then on your calling form check to see if the calendar is loaded. If it is not loaded then do not attempt to set the value.
 
Ah-hah. Right. So this all goes in the same command that opens the calender form, then the OnClick() event for the actual calender selection hides it, at which point i can copy the value across, and then close the form fully.

Interesting.

I'll give it a try, and post the finished code if it works in case anyone else ever needs it.
 
Yes the trick with a dialog form is that the code that calls it stops executing at the line that calls the dialog form to open. When the dialog form is hidden or closes the execution of code resumes from the point at which the code called the dialog form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top