How do I use a variable from a different function in another function

svuyyuru

Registered User.
Local time
Today, 02:03
Joined
Feb 10, 2014
Messages
33
I have one method
Public CurrentFileNameNoExtension As String
Public Sub importexcelfile()
CurrentFileNameNoExtension ="Filename"
'do something
End Sub
I want to use **CurrentFileNameNoExtension** value in **onEnter** event of the dropdown list(**cmvalues**) event. That Value use in sql query. My code is
Private Sub cmvalues_Enter()
Dim qstng As String
qstng = CurrentFileNameNoExtension
Me.cmvalues.RowSourceType = "Table/Query"
Me.cmvalues.RowSource = "Select F1 from " & qstng & " WHERE F1 <> 'MT Model';"
End Sub
But **qstng** value is empty. it is not giving the value in the **importexcelfile()** function.
 
Where is the first line? It should be in a standard module, not behind a form/report. That should make it available anywhere in VBA. Obviously the import sub would have to be run before it would have a value.
 
Method importexcelfile() is in standard module and calls first, CurrentFileNameNoExtension will have the value.
 
In that case the variable should have a value. Can you post the db here, or a representative sample?
 

Users who are viewing this thread

Back
Top Bottom