Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option group issue

Status
Not open for further replies.

punderful

Programmer
Dec 14, 2002
28
0
0
US
I have an option group fraFormSelection with 3 options. The value for these options is 1,2,3. I am trying to write code that will select a form based upon the selection of the option group, placing the form name in the string strFormName for later use (to open the form with filtered records based on selections in other option groups - code I will write later).

When I click the button to select records I get the message:

"The action or method requires a Form Name argument"

This is my code:

Dim strFormName As String
Dim strLinkCriteria As String

If Me!fraFormSelect = 1 Then
strFormName = "frmProjectsSA&Zoning"
ElseIf Me!fraFormSelect = 2 Then
stFormName = "frmProjectsAE"
ElseIf Me!fraFormSelect = 3 Then
stFormName = "frmProjectsPaypoint"
Else
MsgBox "Please select a form", vbExclamation, "Open Form"
End If

DoCmd.OpenForm strDocName, , , strLinkCriteria

Signed,
Punderfully confused yet trying

 
When you're dealing with more than two values, it's usually best to use a Select/Case structure. The If/Then structure will work, but it's a lot easier to read with Select/Case. Also, because Access will have to evaluate the value of the control each time you reference it, it's faster, and thus common practice, to assign the value to a variable, and just test the variable.

Also, you had strDocName in there, probably a hold out from code converted from a macro.

With all that in mind, here's what I'd do with that code snippet:
Dim intFrame as integer
Dim strFormName As String
Dim strLinkCriteria As String

intFrame = me!fraFormSelect
select case intFrame
case 1
strFormName = "frmProjectsSA&Zoning"
case 2
stFormName = "frmProjectsAE"
case 3
stFormName = "frmProjectsPaypoint"
case else
MsgBox "Please select a form", vbExclamation, "Open Form"
End If

DoCmd.OpenForm strFormName, , , strLinkCriteria

Hope this helps.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks for the advice! I did use select/case the 1st round, didn't work there, either. Overall, I knew it was something insanely stupid such as an incorrect name. Option explicit!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top