Passing values between forms and running functions

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
338
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am trying to create a dialog box form (frmUpdateTestCode) that prompts the user to update some information to be processed.

When a user clicks on a button (cmdUpdateTestCode), I want to open the form and pass the other form the ID and Name to be displayed on the frmUpdateTestCode form.

I also want to have the Sub I have on the frmUpdateTestCode form (LoadStudentTestNeed) then run once the information is passed.

How can I do this?

on frmAppointmentScheduling I have :
Code:
Private Sub cmdUpdateTestCode_Click()
 DoCmd.OpenForm "frmUpdateTestCode"
 [Forms]![frmUpdateTestCode]!txtStuID.Value = Me.stuID
 [Forms]![frmUpdateTestCode]!txtLastName.Value = Me.stuLastName
 [Forms]![frmUpdateTestCode]!txtFirstName.Value = Me.stuFirstMiddleName

 DoEvents
End Sub

on frmUpdateTestCode I have
Code:
Private Sub Form_Load()
 LoadStudentTestNeed
End Sub

Sub LoadStudentTestNeed()
'Load Student Test Need
    
    Dim strTestNeededCode As String
    strTestNeededCode = ""
    
    
    'If StudentID is present, check for the most recent test code.
    'If there is a test code, display it on the screen
    
    If (Not IsNull(Me.txtStuID)) And (Me.txtStuID <> vbNullString) _ 
          And Len(Me.txtStuID) = 9 Then
        
        'Verify Student ID
        If VerifyStudentID(Me.txtStuID) Then
            strTestNeededCode = GetTestNeedsCode(Me.txtStuID)
            
            Dim strSQLTC As String 'String for Query
            strSQLTC = "SELECT tblTestInfo.tiTestID, " & _
                       " tblTestInfo.tiEssay As E, " & _
                       " tblTestInfo.tiReading As D, " & _
                       " tblTestInfo.tiMath12 AS M12, " & _
                       " tblTestInfo.tiMath3 AS M3, " & _
                       " tblTestInfo.tiRetest AS RT " & _
                       "FROM tblTestInfo " & _
                       "WHERE (((tblTestInfo.tiTestID)='" & strTestNeededCode & "'))"
    
            
            Dim rsTC As adodb.Recordset 'Record Set to hold TestCode Check Boxes
            Set rsTC = New adodb.Recordset
            rsTC.LockType = adLockReadOnly
            rsTC.CursorType = adOpenStatic
            rsTC.Open strSQLTC
            
            If rsTC.RecordCount = 1 Then
             'If there is a record - update check boxes
                Me.chkReading = rsTC![D]
                Me.chkEssay = rsTC![E]
                Me.chkMath12 = rsTC![M12]
                Me.chkMath3 = rsTC![M3]
                Me.chkRetest = rsTC![RT]
            Else
              'If no record - set check boxes false
                Me.chkReading = False
                Me.chkEssay = False
                Me.chkMath12 = False
                Me.chkMath3 = False
                Me.chkRetest = False
            End If
            
            rsTC.Close
            Set rsTC = Nothing
            
        End If
    End If
    
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I want to open the form and pass the other form the ID and Name to be displayed on the frmUpdateTestCode form.

I guess there's lots of ways to do this. One way is to hide form 1 and let form 2 read the variables from the controls in form 1 (or just leave it open while form 2 opens so the values can be read before form 1 is closed). Another is to pass the values to Form 2 as OpenArgs arguments.
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top