My Assistant
![]() ![]() |
|
|
Jul 20 2004, 12:24 AM
Post
#1
|
|
|
New Member Posts: 6 |
I am having trouble using a Public Const in my form that I set up in a Standard Module. Here is what I have done.
In Standard Module named modStartup I have a line that states the following: Public Const gtxtVersion = "July 19, 2004" I then have a form where I want to display this value. I get an error #2424 stating that It can't find the value. Even msgbox gtxtVersion returns no value. Is there a trick to using a const within a form? It seems so simple yet the solution eludes me. |
|
|
|
Jul 20 2004, 02:32 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 6,250 From: Khon Kaen, Thailand |
Hmm. Try this on OnLoad event of any form and see if you get the right constant.
Private Sub Form_Load() MsgBox gtxtVersion End Sub (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif) |
|
|
|
Jul 22 2004, 10:51 PM
Post
#3
|
|
|
New Member Posts: 6 |
Thanks for your response. The code you suggested is exactly what I used. It does not recognize the global constant I created in the Standard Module. I am not sure where to go from here. I know that Forms (Class Modules) act differently then Standard Modules but I can find little to help me including books and Access Help. ANy ideas?
Thanks again, Stan |
|
|
|
Jul 22 2004, 11:13 PM
Post
#4
|
|
|
Retired Moderator Posts: 11,289 From: Milwaukee, WI |
I believe what is happening is that you have an unhandled error in your code. That is, your code is raising an error and you don't have an error handler to handle it. This causes the values of Public variables to be cleared.
Its not too hard to demonstrate this behavior. Try copying this procedure to a module and then running it from the Immediate window (Ctrl-G): CODE Public gvSID As String ' show public variables are reset on unhandled error Public Sub testPub() Dim nNum As Integer gvSID = "Test string" Debug.Print "gvSID =" & gvSID nNum = 17 / 0 ' divide by zero error Debug.Print gvSID =" & gvSID End Sub Compile that code and then in the Immediate window (Ctrl-G) type testPub and note that the code stops on the divide code. Click on the <End> button. Now go back to the Immediate window and type: ? gvSID Note that you don't get any value where you should get "Test string". Solutions are to have good error handling or avoid Global/Public variables. Another way to do it is to create a class to store variables but that's a bit involved for a quick answer here. |
|
|
|
Jul 22 2004, 11:23 PM
Post
#5
|
|
|
Retired Moderator Posts: 11,289 From: Milwaukee, WI |
Here's a great page with more info about error handling and debugging courtesy of FMS:
http://www.fmsinc.com/tpapers/vbacode/Debug.asp |
|
|
|
Jul 22 2004, 11:27 PM
Post
#6
|
|
|
Retired Moderator Posts: 11,289 From: Milwaukee, WI |
My mistake. Sorry - this does not affect Consts as it does variables. So this is not the problem.
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 06:24 AM |