Solved

Modul variable not recognized other procedure ACCESS 2010

Posted on 2013-12-20
7
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 34

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
Independent Software Vendors: 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete table fields 3 45
MS Excel Pivot Table and MS Access Pivot Table 4 73
ms access - Helpdesk ticket system 5 41
2 Global Vars, 1 List Box 4 25
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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