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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting code to wait for a response from another form

Status
Not open for further replies.

moonraevan

Technical User
Oct 19, 2003
9
0
0
AU
I have some code which opens a form with a calendar control and a continue button on it.

I need the user to choose a date and click the continue button, passing the date to a variable (GetDate) in my code.

I'm having trouble finding a way to get the original code to stop and wait until the user clicks the continue button, so that the GetDate variable doesn't just automatically get today's date and the code keeps going.

I don't want to leave the section of code that I'm running, so transferring the rest of the code to the button's onclick section isn't a solution.

Thanks for your help
 
Open the calendar form in dialog mode, i.e.:

DoCmd.OpenForm "frmMyForm", , , , acDialog

That will suspend execution of the code until the form closes.

Ken S.
 
Thanks Eupher, you hit the nail on the head.

I'm now having trouble getting the date value to pass back to my code. I figure I need GetDate to be a global variable, and to fill it in the continue button code before the dialog box closes but am unsure of how to correctly declare global variables...

 
Nevermind.... I got around it with an invisible text box on my initial form.
 
Here you go!
Add the following code to the OnChange Event of the Calendar control:

Replace AXControlDate with the name of your calendar control

Private Sub AxControlDate_Change()
SetDate(AxControlDate)
End Sub


Be sure to Add the follwing to the Declaration Section of theStandard Module & then add the following 2 procedures.
Dim SelectedDate As Date


Public Sub SetDate(AxControlDate As Date)
SelectedDate = AxControlDate
End Sub

Public Function GetDate()
GetDate = Selecteddate
End Function

This will allow you to pass the Selected date to the global variable , named SelecteDate and you can retieve the same , in any form, by simply assigning GETDate function to a date variable.

Let me know if you need more help.

Good luck!!



 
Just put it in the declarations section of an existing module, or create a module, i.e. from the database window select "Modules", then "New" and under any Option statements at the top, put in:

Public GetDate As Date

Then that variable will be available anywhere in your database you want to use it.

Ken S.
 
Hi guys, thanks for your help...the whole global variable thing seems to be going okay but my date is just coming up as 12:00:00am...

For my calendar form I have this code:

Public Sub CMDContinueTemp_Click()
GETDATE = MSGCalendar.Value
DoCmd.Close
End Sub

Private Sub Form_Load()
MSGCalendar.Value = Date
End Sub

And this is part of the code that calls up the calendar form.

DoCmd.OpenForm "MSGdate", , , , , acDialog
MsgBox "Date is " & GETDATE & ".", vbOKOnly, "Date"

any ideas what I may be doing wrong?
 
I'd put a breakpoint in your code right on the GETDATE = MSGCalendar.Value line and step through the code, then you can see what's actually getting passed to the variable.

What calendar control are you using?

Ken S.
 
It seems to be filling the variable okay while the calendar form is open but not passing it to the other code... I'm thinking maybe my global variables are still wrong although I did what you said...

BTW It's a calendar control 10.0

I think I might just go back to the dodgy version that I had working with the invisible text box; I've tried a few things to get this new version to work and kept running into problems. There are a few bugs in other areas that aren't helping matters either.

Thanks for your help guys
 
Another thing you can try is to set a watch on the GETDATE variable so the code breaks whenever the value changes.

Ken S.
 
I've been watching it the whole time :) (although I like your break on change idea.)

Getdate just empties when the calendar form closes...
 
moonraevan,
What is the Date variable in your following code? Why are you changing the value when the form is loaded?

Code:
Private Sub Form_Load()
MSGCalendar.Value = Date
End Sub
I can't seem to follow siebel2002's solution. There doesn't seem to be an On Change Event for an Activex Control.
Follow Eupher's advice exactly and your code should work without it anyway.
 
it sets the calendar to today's date when the form first loads... I had date() but it took away the brackets. It still worked though.
 
moonraevan,
Don't set the date on the OnLoad event and see what happens. I think if the calendar form is unbound it will default to today's date anyway.
Ed
 
Make sure that the line

Public GetDate As Date

is in a Module, and not behind any form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top