Hello, I am extremely new to VB and Access as well so please bare with me if I do not provide enough information here.
I am attempting to simply take a Command Button which Opens another Form and edit the VB code for this to open a particular form based on the value of an Option Group that is on the same page as the Command Button. I have attempted to add in what few lines of code I thought would make this work to no avail. Please see below and let me know if there is something wrong with the code or simply something wrong with what I am doing in Access.
The Option Group I created has the Labels But1, But2, But3 with default values 1,2,3 respectively.
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim But1 As Integer
If But1 = 1 Then
stDocName = "Form2"
ElseIf But2 = 2 Then
stDocName = "Form3"
ElseIf But3 = 3 Then
stDocName = "Form4"
Else:
stDocName = "Form1"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
Now I would think that you would need to declare the variable in the function definition but access errors when I do this.
Right now the only thing this does is Open up Form1 regardless of the state of But1.
I am attempting to simply take a Command Button which Opens another Form and edit the VB code for this to open a particular form based on the value of an Option Group that is on the same page as the Command Button. I have attempted to add in what few lines of code I thought would make this work to no avail. Please see below and let me know if there is something wrong with the code or simply something wrong with what I am doing in Access.
The Option Group I created has the Labels But1, But2, But3 with default values 1,2,3 respectively.
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim But1 As Integer
If But1 = 1 Then
stDocName = "Form2"
ElseIf But2 = 2 Then
stDocName = "Form3"
ElseIf But3 = 3 Then
stDocName = "Form4"
Else:
stDocName = "Form1"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
Now I would think that you would need to declare the variable in the function definition but access errors when I do this.
Right now the only thing this does is Open up Form1 regardless of the state of But1.