Passing variables from form to query

G

Guest

Dear all,

I want to define the working fields in the forms coding and pass to the
query(I don't want to create the text box object). How to do it ?

Best Regards,
Jason.
 
P

Peter YangMSFT]

Hello Jason,

I understand that you'd like to use parameter query and use form code to
feed the parameters. If I'm off-base, please let me know.

You could use QueryDefs to the query and feed the parameter and run it from
code. Please see the following link for details:

http://www.mvps.org/access/queries/qry0013.htm

Also, you could use following to run query directly by code:

currentdb.Execute

or

docmd.Runsql

More related information:

Using parameters with queries and reports
http://office.microsoft.com/en-us/access/HA011170771033.aspx

If you have further questions or concerns, please feel free to let's know.
Thank you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================
Please note that the newsgroups are staffed weekdays with a goal to provide
ONE BUSINESS DAY RESPONSE to all posts.

If this response time does not meet your needs, please contact CSS for more
immediate assistance:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;OfferProPhone#faq607
 
G

Guest

Hello Peter,

Thank you very much for your help again.

I want to create different forms for running the same query. If I use the
textbox to supply the parameter to query, I need to create different queries
for each forms(the parameter : [forms]![different_forms]![text0]). So that I
want to define the same parameter in different forms and pass to same query.

Could I coding like this:

Option Compare Database
Option Explicit
Public ws_char

Private Sub Command0_Click()
ws_char = "A"
DoCmd.OpenQuery "abc" /*using the parameter "ws_char" in query "abc"*/
End Sub

Best Regards,
Kwong.
 
P

Peter YangMSFT]

Hello Jason,

Per your question, your code may not work as expected. You may need to use
Querydef to do the job.

Set db = CurrentDb
Set qdf = db.QueryDefs("abc")
qdf.Parameters(1) = ws_char
Set rst = qdf.OpenRecordset(dbOpenSnapshot)

Please see the following article on how to bind recordset to a form.

How to bind Microsoft Access forms to ADO recordsets
http://support.microsoft.com/kb/281998

If you have further questions or concerns, please feel free to let's know.
Thank you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter YangMSFT]

Hello Jason,

I'm still interested in this issue. If you have any comments or questions,
please feel free to let's know. We look forward to hearing from you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top