Referencing a Public Variable in multiple modules?

davidb88

Board Regular
Joined
Sep 23, 2013
Messages
76
Hi - Is it possible to reference an established public variable in another module other than the one it was created in? In my database I have a main form page where the user selects a date from the calendar. The way that I have this set up is:

Code:
Public modeldate As Date
'Model Date Select
Sub textModelDate_AfterUpdate()
Dim subseqDate As Date


'set modelDate equal to TextBox
modeldate = Me.textModelDate.Value


'check for month end date selected, if not then set modelDate to 0
subseqDate = DateAdd("d", 1, modeldate)
If Month(subseqDate) = Month(modeldate) Then
    MsgBox "Please choose a month-end date for the Model Run Date."
    modeldate = 0
End If


End Sub

I would like to then be able to reference this variable "modeldate" in other modules but as it stands right now anytime I reference it, nothing appears which makes me think that I am doing something wrong with establishing the variable. Is there an easier way to do this or am I just missing something in the code I have right now?

Thanks!
 
^^ Yep, either I would hide the form rather than actually close it. Or store the variable, either in a public variable in a standard module a la revver's previous post, or by saving the datum in a table where I can retrieve it as needed.

It depends on the situation. What is this date and what are you actually doing with it? How is the form involved in what the user is doing?

Note that with Access 2007 we have the option of using TempVars as a "global" variable without having to use VBA for this.
 
Last edited:
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top