473,404 Members | 2,213 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,404 software developers and data experts.

Help me Toubleshoot SQL cmd, please

I have a form that contains a list box (lstSearch). In the AfterUpdate
event procedure of lstSearch I would like to execute a query. I built
this query in Access and then copied and pasted the SQL into the VB
event procedure. My problem is this: When I update the listbox, VB
throws me an error saying 'RunSQL must execute an SQL statement'. Why
am I recieveing this error? Here is my code:

Private Sub lstSearch_AfterUpdate()

'Set SQL from Queries as Variables
Dim SQLtxtDescription As String
Dim SQLtxtSolution As String
Dim SQLtxtNotes As String
Dim SQLtxtFieldContact As String

If lstSearch.Value = "Problem Description" Then
msgBox "It Worked", 0, "My Test Box"

SQLtxtDescription = "SELECT tblMain.NDate, tblMain.Key,
tblMain.FieldContact, tblMain.PTCContact, tblMain.Equipment,
tblMain.FailureType, tblMain.FailureName, tblMain.LocationName,
tblMain.ProblemDescription, tblMain.ProblemSolution, tblMain.Notes,
tblMain.Resolved FROM tblMain WHERE(((tblMain.ProblemDescription) Like
""*"" & [Enter a Keyword] & ""*""))"

DoCmd.RunSQL (SQLtxtDescription)

End If

End Sub

Jan 2 '07 #1
7 1183
"Grub" <Gr****@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
>I have a form that contains a list box (lstSearch). In the AfterUpdate
event procedure of lstSearch I would like to execute a query. I built
this query in Access and then copied and pasted the SQL into the VB
event procedure. My problem is this: When I update the listbox, VB
throws me an error saying 'RunSQL must execute an SQL statement'. Why
am I recieveing this error? Here is my code:
RunSQL is only for "Action Queries". Queries that APPEND, UPDATE, or DELETE.
It cannot be used for SELECT queries.

What exactly do you want to have happen? Do you want a query datasheet to
appear on the screen? If so, then you need to open a saved query. You cannot
display a code generated SQL statement unless you create a saved QueryDef from
the SQL and then open that.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jan 2 '07 #2

What I have is a query that Searches a particular field using a Keyword
that the user inputs. I implemented this using the this statement in
the Criteria:

Like "*" & [Please Input a Keyword to Search For:] & "*"

My overall goal is to have the user select from the list box the field
to search, then the Afterupdate procedure will determine what the value
was for the field selected (using the IF,THEN,ELSE I have in my code),
run that query for that particular field, and the query asks the user
what word to search for.

Thanks for the help BTW

Grub

Jan 2 '07 #3
"Grub" <Gr****@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
>
What I have is a query that Searches a particular field using a Keyword
that the user inputs. I implemented this using the this statement in
the Criteria:

Like "*" & [Please Input a Keyword to Search For:] & "*"

My overall goal is to have the user select from the list box the field
to search, then the Afterupdate procedure will determine what the value
was for the field selected (using the IF,THEN,ELSE I have in my code),
run that query for that particular field, and the query asks the user
what word to search for.
But what is the purpose of running the query? Running a SELECT query in and of
itself accomplishes nothing. You need a report, form, saved QueryDef, or
control on a form (ListBox, ComboBox) that displays the result of the query
before it is useful for anything.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jan 2 '07 #4
>
But what is the purpose of running the query? Running a SELECT query in and of
itself accomplishes nothing. You need a report, form, saved QueryDef, or
control on a form (ListBox, ComboBox) that displays the result of the query
before it is useful for anything.

Guess I hadn't gotten that far yet. I would like to display the
results in a form.

Jan 2 '07 #5
"Grub" <Gr****@gmail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
>
>>
But what is the purpose of running the query? Running a SELECT query in and
of
itself accomplishes nothing. You need a report, form, saved QueryDef, or
control on a form (ListBox, ComboBox) that displays the result of the query
before it is useful for anything.


Guess I hadn't gotten that far yet. I would like to display the
results in a form.
Then make that query the RecordSource of the form. Then all your code needs to
do is open the form.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jan 2 '07 #6
Grub wrote:
Like "*" & [Please Input a Keyword to Search For:] & "*"
If English is your first language, you might want to make sure you're
using it properly. A lot of developers don't realize how awful their
apps look when the spoken language in which it's written is totally wrong.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jan 2 '07 #7
Thanks Rick..it worked great!

Rick Brandt wrote:
"Grub" <Gr****@gmail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
>
But what is the purpose of running the query? Running a SELECT query in and
of
itself accomplishes nothing. You need a report, form, saved QueryDef, or
control on a form (ListBox, ComboBox) that displays the result of the query
before it is useful for anything.

Guess I hadn't gotten that far yet. I would like to display the
results in a form.

Then make that query the RecordSource of the form. Then all your code needs to
do is open the form.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jan 2 '07 #8

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

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
1
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the ...
0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
12
by: Christo | last post by:
borland c++ 5.01 character constant must be one or two characters long get this when compiling my first c++ program can anyone out there help? it is highlighting this line as the problem ...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
5
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
2
by: =?Utf-8?B?U2NvdHRSYWREZXY=?= | last post by:
I'm creating a doc project for my c# program. I've done this before but this time sonething is wrong. I build my doc project and is succeeds but when I open the help file, there is no documentation...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.