Program control and flow

O

OD

I would like call muilti forms one at a time. Such as getting a date for a
query or report, then call another form. I know that I can call another form
from the form. I'm try to keep my forms more generic, and more private
variables. right now I have to use a lot Public variable.

Example of what I would like to is"

DoCmd.Openform "Date Dialog" {this would return a date}.

?????wait until done with "Date Dialog"

DoCmd.Openform "Print report" {this would allow the user to do something.}

Thanks
OD
 
D

Dirk Goldgar

OD said:
I would like call muilti forms one at a time. Such as getting a date for a
query or report, then call another form. I know that I can call another
form
from the form. I'm try to keep my forms more generic, and more private
variables. right now I have to use a lot Public variable.

Example of what I would like to is"

DoCmd.Openform "Date Dialog" {this would return a date}.

?????wait until done with "Date Dialog"

DoCmd.Openform "Print report" {this would allow the user to do
something.}


Opening a form in dialog mode takes care of the waiting part. That pauses
execution of the calling code until the form is closed or hidden. If you
hide the dialog form instead of closing it, the calling code can then get a
value or values from controls on the form, and then close the dialog form
For example:

'----- code on calling form -----
Dim varDate As Variant

DoCmd.Openform "frmDateDialog", WindowMode:=acDialog

If CurrentProject.AllForms("frmDateDialog").IsLoaded Then
varDate = Forms!frmDateDialog!txtDate
DoCmd.Close acForm, "frmDateDialog", acSaveNo
Else
varDate = Null
End If

If Not IsNull(varDate) Then
DoCmd.OpenReport "rptStuff", _
WhereCondition:="DateField>=" & Format(varDate,
"\#mm\/dd\/yyyy\#")
End If
'----- end code on calling form -----

'----- code on dialog form -----
Private Sub cmdOK_Click()

' cmdOK is a button labeled "OK", that the user clicks
' after entering the date.

If IsNull(Me!txtDate) Then
MsgBox "You didn't enter a date!"
Else
' Hide this form so the calling code can proceed.
Me.Visible = False
End If

End Sub

Private Sub cmdCancel_Click()

' cmdCancel is a button labeled "Cancel", that the user clicks
' if they decide they don't want to do this, after all.

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
'----- end code on dialog form -----
 
O

OD

Thanks Dirk
That helps a lot. I did come up with something so I can call one from then
another after closing the first form.

Example:
Do While varDone <> "No"
DoCmd.OpenForm "Date dialog"
Do While varDone = "No"
DoEvents ' Yield to other processes.
Loop
DoCmd.OpenForm "SelectPrinter"
I do have a public varDone that get set to "Yes" when the user clicks on
the Ok Button.

could you tell me if this going to cause me problems.


Thanks for the help
OD
 
O

OD

Sorry this is the right code

varDone = "Yes"

DoCmd.OpenForm "Date Dialog"
Do While varDone <> "Yes"
DoEvents ' Yield to other processes.
Loop
DoCmd.OpenForm "SelectPrinter"
Thanks
OD
 
D

Dirk Goldgar

OD said:
Sorry this is the right code

varDone = "Yes"

DoCmd.OpenForm "Date Dialog"
Do While varDone <> "Yes"
DoEvents ' Yield to other processes.
Loop
DoCmd.OpenForm "SelectPrinter"

Seems to me your first line ought to be

varDone = "No"

.... if the above approach is to work, unless maybe you set varDone to "No"
in the form's Open event.

In principle, code of that sort should work, but it's not the best way to do
it (in general). Because you're looping, you are using CPU cycles for
nothing. And because you are relying on a global variable, you are subject
to the fragility of such variables -- any unhandled error will reset them.

Better to just open the form in dialog mode, unless you need to keep the
form open and visible after you click the OK button to let the rest of the
code proceed. If you do need to do that, I'd use a control on the form
(probably an invisible one) rather than a public variable.
 

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