Transferring a String value from one Sub to another

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I need to transfer the value of strSection from the click
event sub to the form load sub. below are what I have now
and the strSection value is blank one the form load sub is
activated.

Sub AA_Click()
strSection = "AA"
DoCmd.OpenForm "frmEmp", acNormal
End Sub


Public Sub Form_Load()
Forms![frmEmp]![cobEmp].RowSource = "SELECT
[Application_User_Name]FROM [tblEmployees] WHERE
[section_id] = 'strSection' ORDER BY
[Application_User_Name];"
End Sub

Any help is appreciated

Thanks

-Chris
 
Depending on the version of Access (2002) has many new events to use, but I
believe that the activate event will work for you, as the data is not loaded
yet in the on load event. If you only want this to run once and switch back
and forth between this form and others then a public variable (boolean) can
be used to only run it once. re:
Option Explicit
Public blnRunOnce as Boolean

Private Sub Form_Open()
blnRunOnce = true
End Sub

Private Sub Form_Activate()
If blnRunOnce Then
blnRunOnce = false
Your Code Here
End Sub
 
news.east.earthlink.net said:
Depending on the version of Access (2002) has many new events to use, but I
believe that the activate event will work for you, as the data is not loaded
yet in the on load event. If you only want this to run once and switch back
and forth between this form and others then a public variable (boolean) can
be used to only run it once. re:
Option Explicit
Public blnRunOnce as Boolean

Private Sub Form_Open()
blnRunOnce = true
End Sub

Private Sub Form_Activate()
If blnRunOnce Then
blnRunOnce = false
Your Code Here
End Sub

I need to transfer the value of strSection from the click
event sub to the form load sub. below are what I have now
and the strSection value is blank one the form load sub is
activated.

Sub AA_Click()
strSection = "AA"
DoCmd.OpenForm "frmEmp", acNormal
End Sub


Public Sub Form_Load()
Forms![frmEmp]![cobEmp].RowSource = "SELECT
[Application_User_Name]FROM [tblEmployees] WHERE
[section_id] = 'strSection' ORDER BY
[Application_User_Name];"
End Sub

Any help is appreciated

Thanks

-Chris
Lookup OpenArgs in help.
I think I got the right number of commas.

Sub AA_Click()
strSection = "AA"
DoCmd.OpenForm "frmEmp", acNormal,,,,,strSection <----
End Sub


Public Sub Form_Load()
Forms![frmEmp]![cobEmp].RowSource = "SELECT
[Application_User_Name]FROM [tblEmployees] WHERE
[section_id] = '" & Forms!frmEmp.OpenArgs & "' ORDER BY <----
[Application_User_Name];"
End Sub


Your are not transferring a variable from one subto another. You are
transferring it to
a different form. If you were truly talking about a different
subroutine, then all
you need to do is define the variable in the General Declarations
section of the
form. From there any subroutine in the form can access the variable.


Ron
 
Back
Top