VBA+SQL: Help for beginner

gebli

Registered User.
Local time
Today, 04:41
Joined
Oct 3, 2008
Messages
14
Hi - I hate to ask this question because I'm sure somewhere in the forum is the answer, but I just could not find it and I need to start moving...

Can anybody help me by providing a simple example showing how I can attach a query to a form object? I mean: I need to show several boxes containing several results (of several queries). For example: a box could display the total number of orders placed in Florida, another one the total for New York, etc. So, I think what I need is a piece of VBA code that should run a query based on a parameter (e.g. STATE).

Thanks in advance,

Gerry
 
Hi - I hate to ask this question because I'm sure somewhere in the forum is the answer, but I just could not find it and I need to start moving...

Can anybody help me by providing a simple example showing how I can attach a query to a form object? I mean: I need to show several boxes containing several results (of several queries). For example: a box could display the total number of orders placed in Florida, another one the total for New York, etc. So, I think what I need is a piece of VBA code that should run a query based on a parameter (e.g. STATE).

Thanks in advance,

Gerry


The following code might be behind a Form Button titled "Intl. Shipping / Route":

Code:
Private Sub IntlShippingbyRouteButton_Click()
    DoCmd.OpenQuery "qryInternationalShippingByRoute", acViewNormal, acReadOnly
End Sub

The query qryInternationalShippingByRoute provides a report based on input parameters including shipper name and date range
 
Last edited:
Thanks MSAccessRookie for your prompt feedback.
You did clarify how to run a query from within VBA but where is the returning result stored? That is: if the query is a count(*), how can I display the result in a text box?

Thanks again.
 
Thanks MSAccessRookie for your prompt feedback.
You did clarify how to run a query from within VBA but where is the returning result stored? That is: if the query is a count(*), how can I display the result in a text box?

Thanks again.


Now that's another question entirely! The example that I gave will create a pop-up datasheet containing the results of the query. To display the result in a text box, you need to create a text box with properties that include a recordsource based on the query, and a control source based on the column that contains that data that you want to display.
 
Last edited:
I see... I'll do some research in that direction. Thanks!
 

Users who are viewing this thread

Back
Top Bottom