Setting a string with option groups in Access

T

TrueType

Dear Access Experts,

I am trying to create an Access form which contains an option group
(Frame1) with several entries. After selecting one of these entries the
user should be able to execute the corresponding query by clicking on
the action button (Command1). Unfortunately the action button
"Command1" does not accept the defined string in "Frame1" as the error
message "Method or data member not found" pops up. Can anybody help me
out? Here's my Access code:

____________________________________________________________
Private Sub Frame1_AfterUpdate()
Dim strSelection As String
Select Case Frame1.Value
Case 1
strSelection = "NameofQuery1"
Case 2
strSelection = "NameofQuery2"
End Select

End Sub

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

DoCmd.OpenQuery Frame1.strSelection, acNormal, acEdit

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub
____________________________________________________________


Thanks for your help in advance,
TrueType
 
K

Keith Wilby

TrueType said:
Dear Access Experts,

I am trying to create an Access form which contains an option group
(Frame1) with several entries. After selecting one of these entries the
user should be able to execute the corresponding query by clicking on
the action button (Command1). Unfortunately the action button
"Command1" does not accept the defined string in "Frame1" as the error
message "Method or data member not found" pops up. Can anybody help me
out? Here's my Access code:

____________________________________________________________
Private Sub Frame1_AfterUpdate()
Dim strSelection As String
Select Case Frame1.Value
Case 1
strSelection = "NameofQuery1"
Case 2
strSelection = "NameofQuery2"
End Select

End Sub

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

DoCmd.OpenQuery Frame1.strSelection, acNormal, acEdit

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Try declaring strSelection in the module header and changing

DoCmd.OpenQuery Frame1.strSelection, acNormal, acEdit

to

DoCmd.OpenQuery strSelection, acNormal, acEdit

Regards,
Keith.
www.keithwilby.com
 
T

TrueType

That made it! Thanks for your fast help Keith.

One more question: Is it possible to add a second action button (e.g.
Command2) which automatically exports the chosen query into MS Excel?

Kind regards,
TrueType
 
K

Keith Wilby

TrueType said:
That made it! Thanks for your fast help Keith.

One more question: Is it possible to add a second action button (e.g.
Command2) which automatically exports the chosen query into MS Excel?

Yes, search the help for the "transfer spreadsheet" method.

Regards,
Keith.
www.keithwilby.com
 
T

TrueType

Found it. Unfortunately there seems to be a problem with "strSelection"
again as the following message pops up: "The action or method requires
a table name argument."

______________________________________________________________
Private Sub Command14_Click()

Dim strXLFile As String

strXLFile = InputBox("Enter path of file", "Path of File")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97,
strSelection, strXLFile

End Sub
______________________________________________________________

When entering the Query directly everything works just fine.

Any idea?

Thanks,
TrueType
 
T

TrueType

Please ignore my previous message. Nearly everything is working fine
now!

There's only one small issue: Every time I call up the form I first
have to select/deselect/select one of the opportunities even though
Option "1" is selected by default. Otherwise the string seems to be
empty. Any idea how to solve this?
 
K

Keith Wilby

TrueType said:
Please ignore my previous message. Nearly everything is working fine
now!

There's only one small issue: Every time I call up the form I first
have to select/deselect/select one of the opportunities even though
Option "1" is selected by default. Otherwise the string seems to be
empty. Any idea how to solve this?

Try calling the option group's module in the form's load event:

Call Frame1_AfterUpdate

Regards,
Keith.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top