[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Modul variable not recognized other procedure ACCESS 2010

Posted on 2013-12-20
7
Medium Priority
?
533 Views
Last Modified: 2013-12-20
I have a module level variable declaredas DIM strPath as String at the top of the module.  However, when I run the process to assign I a value, the other procedures do not pick it up, they return null for the strPath.  I tried using Private, but that did not work either.  What am I missing?

Option Compare Database
Option Explicit
Private strPath As String
Private Sub cmdImportNewProjects_Click()

If fntCheckFileList Then Exit Sub
Debug.Print "FILE: " & strPath
Call ImportNewProjects(strPath)
   
End Sub

Private Function fntCheckFileList() As Boolean
Dim strPath As String

If IsNull(Me.FileList) Then
    fntCheckFileList = True
    Exit Function
Else
    strPath = Me.FileList  'This is the full path and file name to be uploaded
    Debug.Print strPath
    fntCheckFileList = False
End If

End Function
0
Comment
Question by:ssmith94015
7 Comments
 
LVL 35

Expert Comment

by:Norie
ID: 39732531
Where is the module?

Does it belong to a form?

Try inserting a standard module (Insert>Module) and putting the declaration there.
0
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 total points
ID: 39732534
Hi,

in your fntCheckFileList function, get rid of the "Dim strPath As String". That is dimensioning a second variable for the function, which is why it is showing as a blank string.

Matt
0
 
LVL 85
ID: 39732545
You can't use Private, of course. You'd need to change it to:

Dim strPath As String

or

Public strPath As String

What type of Module are you using? If this is a Standard Module, then that's all you'd need to do.

If it's a Form Module, then you cannot refer to it directly. Form Modules are Class Modules, and as such are not good choices to hold global variables. The best way to "expose" a value from a Form Module is to either (a) add a hidden textbox on the form, and refer to that directly or (b) add a Property to the class, and provide access to the variable in that manner (note this also works for standard Class modules as well).

(a) Just add a hidden textbox named something like "txtPath", and then refer to it as needed like this:

Forms("MyForm").txtPath

(b) Build a Property statement to give access to the value:

Property Let Path() As String
  Path = strPath
End Property

Now "call" that property from elsewehere in the program:

Dim sPath As String
sPath = Forms("MyForm").Path

Or from a Class module:

Dim cMyClass As cYourClass
cMyClass = New cYourClass

spath = cMyClass.Path
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Expert Comment

by:mbizup
ID: 39732586
In addition to the above comments, it looks like you have strPath declared twice.

If you want to use it as a module level variable (visible to all procedures in a given module), declare it ONCE -- right under option explicit.

As LSM said, don't use the Private

And also, don't Dim it in the individual subs/functions in your module.

Just ONCE:

Dim strPath As String

Open in new window


at the very top of the module.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39732617
the new collection available in A2007 and newer versions "TempVars Collection" is a lot better to use than Public variables..

see this link

http://blogs.office.com/b/microsoft-access/archive/2010/09/27/power-tip-maximize-the-user-of-tempvars-in-access-2007-and-2010.aspx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39732661
I missed mvidas's comment at http:#a39732534 earlier.  My own comment duplicates his post.

(Sorry about that...)
0
 

Author Closing Comment

by:ssmith94015
ID: 39732686
That was it.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question