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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a query based on selection of query name in combobox 1

Status
Not open for further replies.

cdgeer

IS-IT--Management
Joined
Apr 8, 2008
Messages
133
Location
US
I used the wizard to put a combo box on a form with a list of query names. Using store value for later use. I just want to run a query based on the selection. When I try to select the query name from the drop down nothing happens. How do I get the value of my selection to stick. Then maybe I could use a command button to run the query.

I tried this:

Private Sub cmdRunQuery_Click()
On Error GoTo Err_cmdRunQuery_Click
Dim stQueryName As String
Dim stDocName As String

stQueryName = Forms![Access Identity Management].[cmbQueryName]

stDocName = stQueryName
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdRunQuery_Click:
Exit Sub

Err_cmdRunQuery_Click:
MsgBox Err.Description
Resume Exit_cmdRunQuery_Click
 
What happens when you click the command button? Is the command button on the same form as the combo box? If so, you should be able to use:
Code:
Private Sub cmdRunQuery_Click()
On Error GoTo Err_cmdRunQuery_Click
    Dim stQueryName As String
    
    stQueryName = [red][b]Me.[/b][/red][cmbQueryName]

    DoCmd.OpenQuery stQueryName, acNormal, acEdit

Exit_cmdRunQuery_Click:
    Exit Sub

Err_cmdRunQuery_Click:
    MsgBox Err.Description
    Resume Exit_cmdRunQuery_Click
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Yes, but the problem is that I can't select anything from the combo box drop down list. Click... nothing. I can't figure out why my selection doesn't register. When I created the combo box , I selected "save value for later use". Where/ how would the value be stored?
 
What are the significant properties of the combo box?
Name:
Control Source:
Row Source:
Column Count:
Bound Column:
Column Widths:
Enabled:
Locked:


Duane
Hook'D on Access
MS Access MVP
 
I know the properties except the control source are correct.
I'm not sure what I should put for the control source. The list of Query names aren't associated with the table that the form runs off of. I want to just choose a QueryName from the dropdown and then cmd run the query.

I even tried to add a column to the form table that was called QueryName (empty fo course ) but that didn't work either.
 
I guess what I'm trying to say is that I just want to have a dropdown list on a form that I could choose the name of a query and then run that query.
It wouldn't really be bound to anything would it? I want to choose a name and have it stay in the box so I could use that value to run the proper query.
 
ok have you filled in the dropdown with the query names you want to select from? Do you want all the queries in the database available in this dropdown or just some of them?

Leslie

Have you met Hardy Heron?
 
Just some of them.
 
No. Not sure what you mean.
 
Adding a breakpoint is a simple as clicking in the vertical bar to the left of a line of executable code
Code:
|[red][b]o[/b][/red]| [COLOR=white red]  stQueryName = Me.[cmbQueryName][/color]
The code will stop running and allow you to hover the mouse over a variable to see its value. You can press [F8] to step through the code a line at a time. [F5] will run to the end of the procedure.

The following will put the value in the debug window:
Code:
   stQueryName = Me.[cmbQueryName]
   Debug.Print "stQueryName: " & stQueryName

The following will display the value in a message box:
Code:
   stQueryName = Me.[cmbQueryName]
   MsgBox "stQueryName: " & stQueryName


Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane. I just found my mistake. I had some of the Form properties (Allow Additions, Allow Edits, etc.) set to false. I guess I just needed the weekend to take a break and look at it with fresh eyes this morning.
 
Thanks for the Me. correction you helped me with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top