dbTalk Databases Forums  

new query

comp.database.ms-access comp.database.ms-access


Discuss new query in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paja
 
Posts: n/a

Default new query - 11-21-2003 , 08:24 AM






Hi,

I need to make a NEW query with help VB code in Access. In the VB is
not something like createquery, addquery or newquery. Thanks for your
answers.

Paja

Reply With Quote
  #2  
Old   
John
 
Posts: n/a

Default Re: new query - 11-21-2003 , 07:52 PM






I'm going to assume that you are asking for vba code to build and
execute a query in an access code module. If that's not what you need
then please rephrase your question.

strSQL = "Select * FROM tblMyTable WHERE UserID = jobrienct;"
CurrentDb.Execute strSQL

regards,

John
jobrien AT acscience DOT com

paulaza (AT) quick (DOT) cz (Paja) wrote in message news:<d643de58.0311210624.2af21c1 (AT) posting (DOT) google.com>...
Quote:
Hi,

I need to make a NEW query with help VB code in Access. In the VB is
not something like createquery, addquery or newquery. Thanks for your
answers.

Paja

Reply With Quote
  #3  
Old   
Paja
 
Posts: n/a

Default Re: new query - 11-24-2003 , 06:17 AM



Thanks, but "Cannot execute a select query." :-(
I do not wont to make a few new tables.
In my db is a form, where are a few checkboxes and listboxes. The user
will choose his choice. That is all. I need only create new query by
users choice.
Sorry, my bad english :-)

Paja


jobrienct (AT) excite (DOT) com (John) wrote in message news:<c4916e0f.0311211752.98b02e8 (AT) posting (DOT) google.com>...
Quote:
I'm going to assume that you are asking for vba code to build and
execute a query in an access code module. If that's not what you need
then please rephrase your question.

strSQL = "Select * FROM tblMyTable WHERE UserID = jobrienct;"
CurrentDb.Execute strSQL

regards,

John
jobrien AT acscience DOT com

paulaza (AT) quick (DOT) cz (Paja) wrote in message news:<d643de58.0311210624.2af21c1 (AT) posting (DOT) google.com>...
Hi,

I need to make a NEW query with help VB code in Access. In the VB is
not something like createquery, addquery or newquery. Thanks for your
answers.

Paja

Reply With Quote
  #4  
Old   
John
 
Posts: n/a

Default Re: new query - 11-25-2003 , 08:03 AM



woops, yep, exexcute is for action queries. I was up late i guess.
Sorry about that, you can create your query and then use DoCmd to save
it to disk. Is that what you need to do?

John

paulaza (AT) quick (DOT) cz (Paja) wrote in message news:<d643de58.0311240417.25c34439 (AT) posting (DOT) google.com>...
Quote:
Thanks, but "Cannot execute a select query." :-(
I do not wont to make a few new tables.
In my db is a form, where are a few checkboxes and listboxes. The user
will choose his choice. That is all. I need only create new query by
users choice.
Sorry, my bad english :-)

Paja


jobrienct (AT) excite (DOT) com (John) wrote in message news:<c4916e0f.0311211752.98b02e8 (AT) posting (DOT) google.com>...
I'm going to assume that you are asking for vba code to build and
execute a query in an access code module. If that's not what you need
then please rephrase your question.

strSQL = "Select * FROM tblMyTable WHERE UserID = jobrienct;"
CurrentDb.Execute strSQL

regards,

John
jobrien AT acscience DOT com

paulaza (AT) quick (DOT) cz (Paja) wrote in message news:<d643de58.0311210624.2af21c1 (AT) posting (DOT) google.com>...
Hi,

I need to make a NEW query with help VB code in Access. In the VB is
not something like createquery, addquery or newquery. Thanks for your
answers.

Paja

Reply With Quote
  #5  
Old   
Bryan Christopher
 
Posts: n/a

Default Re: new query - 11-25-2003 , 01:30 PM



paulaza (AT) quick (DOT) cz (Paja) wrote in message news:<d643de58.0311210624.2af21c1 (AT) posting (DOT) google.com>...
Quote:
Hi,

I need to make a NEW query with help VB code in Access. In the VB is
not something like createquery, addquery or newquery. Thanks for your
answers.

Paja
Hello Paja:

You can create a qry using VB/VBA using the following snipit (this
does not have to be a function, but it is in my case):

Function Makeqry(qryNam, strSQL)
On Error GoTo Err_Makeqry

Dim mdb As Database
Dim qdf As QueryDef

Set mdb = CurrentDb
Set qdf = mdb.CreateQueryDef("" & qryNam)

strSQL = "" & strSQL

qdf.SQL = strSQL
Exit_Makeqry:
Exit Function
Err_Makeqry:
MsgBox Error$
Resume Exit_Makeqry
End Function

Using this function, I can pass any query name I wish as well as any
SQL statement I wish; the function will then take the SQL, make the
query, and save it using whatever string I pass along as the name.

Keep in mind that you can use variables to dynamically assign criteria
in SQL before creating/recreating a query such as:

Private Sub
Dim strFName as String
Dim strSQL as string

strFName="Frank"
strSQL = "SELECT tblContacts_Name.*, tblContacts_Name.FName " _
& "FROM tblContacts_Name " _
& "WHERE (((tblContacts_Name.FName)=" & strFName & "));

Makeqry "qryFindFrank", strSQL
End Sub

So, there you go; you have made a query with dynamic criteria using
VB. Now, use this methodology to retrieve data from the form, assign
that data to a variable, and use the variable in your SQL to create
queries dynamically based on what information is selected/displayed on
the form.

Hope this works for you!

Bryan


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.