473,231 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Creating a Query in VB

How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.
Nov 12 '05 #1
7 5928
Simon,

Lookup QueryDef in the Help file.
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.

Nov 12 '05 #2
cheat . .
create the query as a normal query , then view the SQL code for it . . copy
this to the clipboard and paste it into your vba code . . you will need to
fiddle it a bit to make it work . . since you must create a final text
string that can be executed with a DoCmd.RunSql command.

cheers
paul g
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.

Nov 12 '05 #3
The SQL for a query is simply text. Given that I don't have any idea what
data you have and what information you want, I couldn't be specific. You can
use the Query Builder to create a Query, switch to SQL view to get a
"headstart" -- writing SQL from scratch is needless effort. You can then
copy that SQL, modify as needed (for example, adding a WHERE clause to limit
the records returned) and use VBA DAO code to execute it.

Larry Linson
Microsoft Access MVP

"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.

Nov 12 '05 #4
"Larry Linson" <bo*****@localhost.not> wrote in message news:<w_*****************@nwrddc02.gnilink.net>...
The SQL for a query is simply text. Given that I don't have any idea what
data you have and what information you want, I couldn't be specific. You can
use the Query Builder to create a Query, switch to SQL view to get a
"headstart" -- writing SQL from scratch is needless effort. You can then
copy that SQL, modify as needed (for example, adding a WHERE clause to limit
the records returned) and use VBA DAO code to execute it.

Larry Linson
Microsoft Access MVP

"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.


Thanks for the help. I have tried the DoCmd.RunSQl command. So far I have written:

Private Sub Command0_Click()
DoCmd.RunSQL (SELECT StationName FROM tblproblem WHERE StationName = "H7-11")
End Sub

It doesnt seem to work. Any one have any ideas?
Nov 12 '05 #5
Did you look at the Help for RunSQL? It is for running action queries (e.g.,
delete, append, maketable...) but yours is a Select Query. What is it that
you want to _do_ with the data retrieved from this query?

If it is to edit the information, you might want to consider opening a form
based on the query. You can run a select query with DoCmd.OpenQuery. It
seems rare that you'd want to give a user access to the datasheet view of a
query that you opened from code, though, because there are so many things
the user can inadvertently do wrong from datasheet view.

Larry Linson
Microsoft Access MVP
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
"Larry Linson" <bo*****@localhost.not> wrote in message news:<w_*****************@nwrddc02.gnilink.net>...
The SQL for a query is simply text. Given that I don't have any idea what data you have and what information you want, I couldn't be specific. You can use the Query Builder to create a Query, switch to SQL view to get a
"headstart" -- writing SQL from scratch is needless effort. You can then
copy that SQL, modify as needed (for example, adding a WHERE clause to limit the records returned) and use VBA DAO code to execute it.

Larry Linson
Microsoft Access MVP

"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
How do you created a query in VB?
I have a button on a form that signifies a certain computer in a
computer suite. On clicking on this button i would like to create a
query searching for all details invovling that computer, for the user
to then view.
Any ideas on some code?

Many thanks for any help.


Thanks for the help. I have tried the DoCmd.RunSQl command. So far I have

written:
Private Sub Command0_Click()
DoCmd.RunSQL (SELECT StationName FROM tblproblem WHERE StationName = "H7-11") End Sub

It doesnt seem to work. Any one have any ideas?

Nov 12 '05 #6
"Larry Linson" <bo*****@localhost.not> wrote in message news:<M1***************@nwrddc03.gnilink.net>...
Did you look at the Help for RunSQL? It is for running action queries (e.g.,
delete, append, maketable...) but yours is a Select Query. What is it that
you want to _do_ with the data retrieved from this query?

If it is to edit the information, you might want to consider opening a form
based on the query. You can run a select query with DoCmd.OpenQuery. It
seems rare that you'd want to give a user access to the datasheet view of a
query that you opened from code, though, because there are so many things
the user can inadvertently do wrong from datasheet view.

Larry Linson
Microsoft Access MVP
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
"Larry Linson" <bo*****@localhost.not> wrote in message

news:<w_*****************@nwrddc02.gnilink.net>...
The SQL for a query is simply text. Given that I don't have any idea what data you have and what information you want, I couldn't be specific. You can use the Query Builder to create a Query, switch to SQL view to get a
"headstart" -- writing SQL from scratch is needless effort. You can then
copy that SQL, modify as needed (for example, adding a WHERE clause to limit the records returned) and use VBA DAO code to execute it.

Larry Linson
Microsoft Access MVP

"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
> How do you created a query in VB?
> I have a button on a form that signifies a certain computer in a
> computer suite. On clicking on this button i would like to create a
> query searching for all details invovling that computer, for the user
> to then view.
> Any ideas on some code?
>
> Many thanks for any help.


Thanks for the help. I have tried the DoCmd.RunSQl command. So far I have

written:

Private Sub Command0_Click()
DoCmd.RunSQL (SELECT StationName FROM tblproblem WHERE StationName =

"H7-11")
End Sub

It doesnt seem to work. Any one have any ideas?


Thanks for your help Larry. Basically, i want to create a query to
view as a report or likewise. I will be clicking on a button that
significies a certain computer in a certain room and the guery will
search and for all previous problems with that computer, the search
will be from tblproblem.
The help file on VBA has been of little help to me unfortunately,
however much i stare at it!!

Thanks again
Nov 12 '05 #7
You can either create the SQL and pick it up in the Open event of the Report
to replace the Report's RecordSource, or store it in the SQL property of the
Query used as the Report's RecordSource; or you can use the
DoCmd.OpenReport's WhereCondition argument to select the particular
information. The first method is somewhat more efficient in all cases, and a
great deal more efficient in a client-server environment; it is also a great
deal more efficient in a split-database over-the-network multiuser
environment IF the criteria fields are indexed.

In any case, you will not run the query... you'll just use it as the
RecordSource of the Report, or the "WHERE clause without the WHERE" as the
WhereCondition of DoCmd.OpenReport.

Good luck.

Larry Linson
Microsoft Access MVP
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
"Larry Linson" <bo*****@localhost.not> wrote in message

news:<M1***************@nwrddc03.gnilink.net>...
Did you look at the Help for RunSQL? It is for running action queries (e.g., delete, append, maketable...) but yours is a Select Query. What is it that you want to _do_ with the data retrieved from this query?

If it is to edit the information, you might want to consider opening a form based on the query. You can run a select query with DoCmd.OpenQuery. It
seems rare that you'd want to give a user access to the datasheet view of a query that you opened from code, though, because there are so many things the user can inadvertently do wrong from datasheet view.

Larry Linson
Microsoft Access MVP
"Simon Bailey" <go*********@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
"Larry Linson" <bo*****@localhost.not> wrote in message

news:<w_*****************@nwrddc02.gnilink.net>...
> The SQL for a query is simply text. Given that I don't have any idea

what
> data you have and what information you want, I couldn't be specific. You
can
> use the Query Builder to create a Query, switch to SQL view to get a
> "headstart" -- writing SQL from scratch is needless effort. You can
then > copy that SQL, modify as needed (for example, adding a WHERE clause to limit
> the records returned) and use VBA DAO code to execute it.
>
> Larry Linson
> Microsoft Access MVP
>
> "Simon Bailey" <go*********@hotmail.com> wrote in message
> news:1c**************************@posting.google.c om...
> > How do you created a query in VB?
> > I have a button on a form that signifies a certain computer in a
> > computer suite. On clicking on this button i would like to create
a > > query searching for all details invovling that computer, for the user > > to then view.
> > Any ideas on some code?
> >
> > Many thanks for any help.

Thanks for the help. I have tried the DoCmd.RunSQl command. So far I

have written:

Private Sub Command0_Click()
DoCmd.RunSQL (SELECT StationName FROM tblproblem WHERE StationName =

"H7-11")
End Sub

It doesnt seem to work. Any one have any ideas?


Thanks for your help Larry. Basically, i want to create a query to
view as a report or likewise. I will be clicking on a button that
significies a certain computer in a certain room and the guery will
search and for all previous problems with that computer, the search
will be from tblproblem.
The help file on VBA has been of little help to me unfortunately,
however much i stare at it!!

Thanks again

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
4
by: Jeremy Weiss | last post by:
Thanks to much help from everyone in my previous thread, I've made it a pretty fair ways into my billing/invoicing db. I'm now needing a way to cycle through all the records in a table and create...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
2
by: deja | last post by:
Hello, I am creating an a to z list - basically a count of all results that start with the letter "A", "B", "C" .... and so on. I am pretty poor at SQL so I am sure some brains out there can...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
4
by: DeanL | last post by:
Hi Guys, I need some help creating a query that is going to take between 1 and 10 parameters. The parameters are entered on a form into text boxes that may have data or be empty. Is there a...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
3
LMHelper
by: LMHelper | last post by:
How do I create a table from a query that will UPDATE each time I update the original table? I created a table from a query and it stayed the same for the past couple of months and did not...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.