Hi everybody,
Using Access 2003.
I'm trying to dynamically set the record source for the current form and set the control source for a text box to input data to one of three tables.
I have a form (frmAddNewUser) that will add users to one of three separate tables (tblDefsAFP, tblDefsMSU, tblDefsWF) based on the selection of an option button from an option group on the same form.
I have a textbox (txtNewUser) that accepts the name of the user and will have it's control source set by one of the three option buttons below it.
So, to recap, the user name is entered in a text box, one of the option buttons should be selected, and based on the selection of the option button, the record source for the form should be determined and the control source for the text box should be determined.
Oh, and everything launches based on a submit button.
Right now it accepts everything as if it's working, but the name entered into the text box isn't appearing in the table/query specified.
Here's the code:
Thanks, in advance, for the help
Using Access 2003.
I'm trying to dynamically set the record source for the current form and set the control source for a text box to input data to one of three tables.
I have a form (frmAddNewUser) that will add users to one of three separate tables (tblDefsAFP, tblDefsMSU, tblDefsWF) based on the selection of an option button from an option group on the same form.
I have a textbox (txtNewUser) that accepts the name of the user and will have it's control source set by one of the three option buttons below it.
So, to recap, the user name is entered in a text box, one of the option buttons should be selected, and based on the selection of the option button, the record source for the form should be determined and the control source for the text box should be determined.
Oh, and everything launches based on a submit button.
Right now it accepts everything as if it's working, but the name entered into the text box isn't appearing in the table/query specified.
Here's the code:
Code:
Private Sub cmdSubmitAddNewUser_Click()
Dim subVal As Variant
Dim savVal As Variant
Dim UserChoice As Variant
If IsNull(Me.NewUser) Then
MsgBox "You must enter a user name", vbOKOnly + vbExclamation, "Empty User Name"
Exit Sub
End If
UserChoice = [optionGroup].Value
If IsNull(UserChoice) Then
MsgBox "You must select a campus", vbOKOnly + vbExclamation, "Campus Error"
Exit Sub
End If
If UserChoice = 1 Then
Me.RecordSource = "qryAuditorAFP"
'for debugging purposes
MsgBox Me.RecordSource & " me.name " & Me.Name
Me.txtNewUser.ControlSource = "Auditor"
MsgBox Me.NewUser.ControlSource
ElseIf UserChoice = 2 Then
Me.RecordSource = "qryAuditorMSU"
Me.txtNewUser.ControlSource = "Auditor"
ElseIf UserChoice = 3 Then
Me.RecordSource = "qryAuditorWF"
Me.txtNewUser.ControlSource = "Auditor"
End If
subVal = MsgBox("Are you sure you want to submit?", vbYesNo + vbQuestion, "Add User")
If subVal = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, Me.Name
MsgBox "User was entered successfully", vbOKOnly + vbInformation, "User Added"
savVal = MsgBox("Would you like to enter another user?", vbYesNo + vbQuestion, "Add User")
If savVal = vbYes Then
DoCmd.OpenForm "frmAddNewUser", acNormal
ElseIf savVal = vbNo Then
DoCmd.OpenForm "Switchboard", acNormal
End If
ElseIf subVal = vbNo Then
MsgBox "User was not added", vbOKOnly + vbInformation, "User Not Added"
DoCmd.CancelEvent
End If
End Sub
Comment