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!

pass variables to form in dialog mode 3

Status
Not open for further replies.

TAMSIN

Programmer
Sep 6, 2000
31
0
0
GB
Hi,
Not sure what the best approach to this would be. I have a button which opens a form in dialog mode, which I want to pass three integers to, to use to set up the contents of some combos etc. But because its in dialog mode, the code after DoCmd.OpenForm .. doesn't run til its closed. And because I open it from several places the variable values don't always come from the same place, so I can't easily do something in the onLoad event to get the values.
Options I have thought of are:
1. Pass all the integers as a comma delimited string to the openargs property, and then parse this when the form opens to get the integers.
2. Set up some cases for where the integers come from, pass a single flag to the openargs and then depending on the case use the onLoad event to get the integer values from specific places on already open forms.
Neither of these seem very neat! - am I missing something/does anyone know a nicer way to do this?
Thanks!
 
Theoretically, you can Load the form, set some public variables in it, and then .Show it. That's what you'd do in "real" VB (as opposed to VBA). I haven't had much luck getting that to work in Access, though. (I have opened a dialog from a standard module this way, but if I try to do it form a Form, Access crashes.)

Your techniques are good alternatives. Another is to set up some public variables in a standard module, and give them values before you open the dialog; the dialog's OnLoad can then use the public variables. It's just as kludgy as your two techniques, but at least it's an alternative. Rick Sprague
 
Tasmin,

did you find an easier way to do this as I have the same problem.

stuart.
 
I've used properties in the form quite successfully. While global variables will work I find them unreliable at times as an untrapped error will sometimes cause a lost global variable value but never a lost form property.

I use the properties below to allow the user to cancel a long running function. I merely check from the code if the form is loaded then get the property value. If the CancelOn property has been set on the form then I cancel the function at the end of a loop. If you use something like this then you need a DoEvents subroutine call embedded in your application code. This is somewhat different from what you are asking but the same concept is a viable solution. You could actually pass type data structures to the form consisting of various types of data and use it in the OnLoad or OnOpen events.

You can parse data from the OpenArgs parameter but I prefer using the properties since I can, if I want and set the properties to public, query what the values are from anywhere in code and also write the validation code much easier.

Public Property Get CancelOn() As Boolean

' IR# 99-0003, SCK, Cancel Scheduler Report Generation
CancelOn = prpbCancelOn

End Property

Public Property Let CancelOn(ByVal bNewValue As Boolean)

' IR# 99-0003, SCK, Cancel Scheduler Report Generation
prpbCancelOn = bNewValue
With Me
If prpbCancelOn = True Then
.TRCCode.SetFocus
.btnCancel.Enabled = True
.btnExit.Enabled = False
Else
.TRCCode.SetFocus
.btnCancel.Enabled = False
.btnExit.Enabled = True
End If
End With

End Property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top