By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

Carrying variables across forms.

devonknows
100+
P: 137
Hi, im having trouble carrying variables across a form, ive looked on here and other sites but cant find anything that helps me, or i might not be searching for the right terms, so i though i would post to see if anyone can help me.
what i need is to carry certain aspects of data from splash form to my main form which im currently developing.

this is the code im usign for the frmSplash

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
Private Sub Form_Load()
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Image1.Height = 615
Dim db_file As String
lbversion.Caption = "Version: " & App.Major & "." & App.Minor & "." & App.Revision
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
db_file = db_file & "AlbumData.mdb"
Dim a$
Dim b$

b$ = db_file


On Error GoTo filenotfound
a$ = GetAttr(b$)

' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
Exit Sub
me.hide
form1.show
filenotfound:
MsgBox "The Database file: " & db_file & vbCrLf & "Cannot be found, please make sure that it exists and run again.", vbCritical, "File not Found"
Unload Me
End Sub

what i want to do is carry the variables " db_file " and " conn " across to form1 so for example i could do
label1.caption = "" & db_file or
test1.text = "" & db_file

but if anyone can help me in showing me how i can do that i would be most greatful. thank you very much.

Kind Regards,
Devon.
Dec 3 '06 #1
Share this Question
Share on Google+
1 Reply


sashi
Expert 100+
P: 1,754
Hi, im having trouble carrying variables across a form, ive looked on here and other sites but cant find anything that helps me, or i might not be searching for the right terms, so i though i would post to see if anyone can help me.
what i need is to carry certain aspects of data from splash form to my main form which im currently developing.

this is the code im usign for the frmSplash

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
Private Sub Form_Load()
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Image1.Height = 615
Dim db_file As String
lbversion.Caption = "Version: " & App.Major & "." & App.Minor & "." & App.Revision
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
db_file = db_file & "AlbumData.mdb"
Dim a$
Dim b$

b$ = db_file


On Error GoTo filenotfound
a$ = GetAttr(b$)

' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
Exit Sub
me.hide
form1.show
filenotfound:
MsgBox "The Database file: " & db_file & vbCrLf & "Cannot be found, please make sure that it exists and run again.", vbCritical, "File not Found"
Unload Me
End Sub

what i want to do is carry the variables " db_file " and " conn " across to form1 so for example i could do
label1.caption = "" & db_file or
test1.text = "" & db_file

but if anyone can help me in showing me how i can do that i would be most greatful. thank you very much.

Kind Regards,
Devon.
Hi there,

At the moment you have declared these variables as local variable, you need to declare a variable as public for a longer scope. Please refer below modified code segment, i've moved these variables to a module file.

Kindly refer below attached links for further reading & understanding, hope it helps. Good luck & Take care.

Variable Declaration in Visual Basic
Variable Scope

Module code
Expand|Select|Wrap|Line Numbers
  1.   Public conn As ADODB.Connection
  2.   Public rs As ADODB.Recordset
  3.  
  4.   Public db_file As String
  5.  
Dec 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.