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

How to Pass variable value from one form to another

100+
P: 134
I have no exactly idea how to pass a variable value from one form to another, How do I do it using, say in Form 1 using DoCmd.OpenForm like the below statement, correct me If I am wrong.

FORM_1
Dim msg As String
strlsql = "Hello"
DoCmd.OpenForm "frmPO", acViewNormal, , msg

Then on the 2nd Form -FORM_2, Should I detect it from the Form_load ? .

FORM_2 (Form_Load)

IF msg = 'bla bla" then
do this ...........................

Endif
Dec 26 '06 #1
Share this Question
Share on Google+
2 Replies


missinglinq
Expert 2.5K+
P: 3,532
You use the last argument of the OpenForm command, openargs. strMessage is assigned to openargs in Form1, then retieved in Form2

Expand|Select|Wrap|Line Numbers
  1. 'On the first form 
  2. Private Sub Goto2ndForm_Click()
  3. Dim strMessage as String    
  4.    strMessage = "bla bla" 
  5.    DoCmd.OpenForm "2ndForm", , , , , , strMessage
  6. End Sub
  7.  
  8. 'On the second form
  9. Private Sub Form_Load()
  10.     If OpenArgs = "bla bla" Then
  11.       'Do whatever
  12.     End If
  13. End Sub
Dec 26 '06 #2

100+
P: 134
You use the last argument of the OpenForm command, openargs. strMessage is assigned to openargs in Form1, then retieved in Form2

Expand|Select|Wrap|Line Numbers
  1. 'On the first form 
  2. Private Sub Goto2ndForm_Click()
  3. Dim strMessage as String    
  4.    strMessage = "bla bla" 
  5.    DoCmd.OpenForm "2ndForm", , , , , , strMessage
  6. End Sub
  7.  
  8. 'On the second form
  9. Private Sub Form_Load()
  10.     If OpenArgs = "bla bla" Then
  11.       'Do whatever
  12.     End If
  13. End Sub
Thanks so much, got your message, it working now.
Dec 26 '06 #3

Post your reply

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