I have a program built with VBA, in access. I have a form with the field chDate and I need to get the value of the field in a module file named Global (not class module).
<If you can provide some sample code, it might help us in trying to get you a solution.
Here's what might work:
Dim
an object as an instance of your form, and set the instance to a new instance. These two lines will do that (assuming the form is called frmForm
)
Dim theForm as frmForm
Set theForm = new frmForm
then Show that Form:
theForm.show
The form will get the focus, so you can populate the fields. At that point, once the form is hidden, your code should be able to pull the field as such:
var1 = theForm.txtFormField.Text
However, if you unload the form in code, all variables directly tied to the form will be lost. In that case, you might want to follow Oneide's example, and set a global variable to the value of the form field. You can do this in one of the form's event handlers.
As far as I know, you're trying to get the data the wrong way.
Anytime you would try to get your form data, from a standard module, your form probably will already be closed or, if you're not opening it as a restricted window, the value will not be ready yet.
Anyway, if you could get pass through all the difficulties above, you're probably coding in a not standard / right way.
Remember that VBA is an event driven language, and you would be better using it's strenghts rather than fighting against them.
As a final word, if this is just a casual coding, I suggest you using a global variable and make de Code Behind Form have set it up on control's change event.
If you're not sure what I mean, please leave a comment and I'll try to explain it better.
And, if you don't mind, let us know more about your starting code to get better answers.
Let me see if I can recall my Access days. In your global module you should access the form field be prefixing the form name i.e. var1 = Form1.txtFirmField.Text