Solved

Modul variable not recognized other procedure ACCESS 2010

Posted on 2013-12-20
7
522 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

773 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