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

Dynamic Query Problems!!!!

Status
Not open for further replies.

Kckronic21

Programmer
Jul 29, 2001
81
US
I have a problem. I am trying to create a dymanic query on a form. Here is my SQL statement:

SELECT [Forms]![Select_Form]![Table_txtbox].[Forms]![Select_Form]![Field_txtbox]
FROM [Forms]![Select_Form]![Table_txtbox]
WHERE ((([Forms]![Select_Form]![Table_txtbox].[Forms]![Select_Form]![Field_txtbox])=[Forms]![Select_Form]![City_txtbox]));

I have created the necessary textboxes on the form and a button that runs the query, but it will not work.
Please tell me what I am doing wrong. Thanks!!!
 

It would be helpful if you posted the code in the button click event. I assume that you assign your SQL string to a variable and then execute the string. If this is so, then you need code in such a way that VB interprets the value in the text boxes and not the names of the text boxes. Try the following.

Dim strSQL As String

strSQL="SELECT t." & [Forms]![Select_Form]![Field_txtbox] &
" FROM " & [Forms]![Select_Form]![Table_txtbox] &
" AS t WHERE t." & [Forms]![Select_Form]![Field_txtbox] &
"=" & [Forms]![Select_Form]![City_txtbox] & ";"


NOTE: I used an alias (t) for the table name to shorten the code and improve readability. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Hi I'm in huge trouble. HEEEELPPPP PPPLEASE.I created a macro that went horribly wrong. I have 15 different forms linked to the Main Menu.Well this is wat i did.

Macro builder saved as autoexec
ACTION DESCRIPTION
Open Form %W
Close %H
Open Form %1
Msg Box Watup this should work...

Now when I load my file the message comes up thus crashing the prog. any button i press nothing happens
PLEASE dont tell me i have 2 restart my forms
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top