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

Is there an easy way to convert query to code

Status
Not open for further replies.

lewie

Technical User
Joined
Jan 17, 2003
Messages
94
Location
US
I converted macro's to code using save as module; Is tyhere an easy way to convert queries also.
TIA
Lewie
 
Sure... depends upon what u need to do...

Dim thisDB as DAO.Database
Dim lcSQL as string
Set ThisDB = CurrentDB

lcSQL = "Select f1, f2, f3 From Table Where F1='2';"
ThisDB.EXECUTE lcSQL, dbFailOnErrorr

This will run code...

? htwh,

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
I've coverted a macro to module. It was saved as a function. How would I go about changing it to a sub and moving it to the button I want it placed under.
 
Ok i got it saved under the control in the form as a sub. It runs alot faster then when calling as a function. Now how do I reference a field in a database I want to compare.
Is it [database][field] = some value.
 
Just like you would for a regular SQL Statement...

Select fields
From Table
Where Field <Condition>.

But, for date fields, you need to use a # symbol and text fields a single quote '.

F1 = Text
F2 = Date
F3 = Double (Numeric)

lcSQL = lcSQL & &quot;WHERE F1 = '&quot; & variable or field & &quot;'&quot;

lcSQL = lcSQL & &quot;WHERE F2 = #&quot; & variable or field & &quot;#&quot;

lcSQL = lcSQL & &quot;WHERE F3 = &quot; & variable or field & &quot;&quot;

htwh,

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
I used a field on the form where it is selected and it was just [field]= &quot;text value&quot;
here are some queries i am running how would i convert them to code.....

DoCmd.OpenQuery &quot;LB Make DTR table&quot;, acViewNormal, acEdit
DoCmd.OpenQuery &quot;LB Append DTR to DTR master #&quot;, acViewNormal, acEdit
DoCmd.OpenQuery &quot;LB update DTR # part 1&quot;, acViewNormal, acEdit
DoCmd.OpenQuery &quot;LB update DTR # part 2&quot;, acViewNormal, acEdit
DoCmd.OpenQuery &quot;LB last Update DTR ID to LB Master&quot;, acViewNormal
Thanks alot
I appreciate your help
 
If i highlite the query and switch to design mode i get the design menu bar. If i select sql view it will show me the sql code. Can i run the sql code in a module??/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top