Click Button to Open Form

joebobku

New member
Local time
Today, 13:20
Joined
Jun 22, 2009
Messages
2
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.
 
1. The option group FRAME is the part you check the value against.

2. You are using stLinkCriteria but you haven't given it a value.

stLinkCriteria = "[FieldOnNewFormToMatch] = " & Me!YourOptionGroupFrameNameHere
 
I suppose I don't understand this stLinkCriteria. Can you please expound upon this along with what you mean by FieldOnNewFormToMatch. I apologize but I just delved into VB today. I have a lot of programming exp just not VB.

Thanks,
 
stLinkCriteria is something you are going to be passing to the other form so that it basically "filters" the form that is opening to be what you want. You need to tell it what to look for. So, when you open your other form you want it to open to a specific record, or set of records, correct? So you need to basically tell it what you want. I want all records that match what I have selected on my form I am currently on.

If you just want to open the other form with the full set of records in its recordsource, just get rid of the stLinkCriteria part (including the Dim stLinkCriteria...) completely.
 
Take a look at this little example...might give you some ideas...
 

Attachments

Users who are viewing this thread

Back
Top Bottom