Solved

Modul variable not recognized other procedure ACCESS 2010

Posted on 2013-12-20
7
519 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 33

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 500 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 84
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 119

Expert Comment

by:Rey Obrero
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now