469,626 Members | 889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Carrying variables across forms.

devonknows
137 100+
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
1 4824
sashi
1,754 Expert 1GB
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.

Similar topics

3 posts views Thread by Ralph Freshour | last post: by
3 posts views Thread by Jessica Loriena | last post: by
1 post views Thread by Ani | last post: by
4 posts views Thread by Cowboy \(Gregory A. Beamer\) | last post: by
1 post views Thread by Ricardo Furtado | last post: by
7 posts views Thread by Japhy | last post: by
5 posts views Thread by Sandman | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.