473,386 Members | 1,785 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,386 software developers and data experts.

Returning VB Executed SQL String to a Form

I'm running the following code but it keeps failing because Select
isn't a part of the action query method:

Private Sub Command2_Click()
Dim SQLStr As String

SQLStr = "SELECT Request.RequestID, Request.ReqName, Request.ReqDesc
FROM Request"
DoCmd.RunSQL SQLStr
'Debug.Print SQLStr

End Sub

How does one execute a SQL select statement through VB that's linked
to a button and return the results to a form (that the button reside
on)? I'm assuming that this is a varily simple procudure but i'm
really stumped! Thanks in advance.
Louis
Nov 12 '05 #1
5 7722
On 7 Nov 2003 10:57:31 -0800, Louis wrote:
SQLStr = "SELECT Request.RequestID, Request.ReqName, Request.ReqDesc
FROM Request"
DoCmd.RunSQL SQLStr
'Debug.Print SQLStr


DoCmd.RunSQL is used for action queries, starting with UPDATE, DELETE etc.
You need to assign the SQL statement to the form's record source:

another form:
Forms!YourFormName.RecordSource = SQLStr

your current form:
Me.RecordSource = SQLStr

HTH - Peter

--
No mails please.
Nov 12 '05 #2
I knew if i posted a short question it wouldn't work. My fault.
Here's what i'm trying to do.

I have multiple drop down filters and based on the combination of the
drop down I want to pass that information to a parameter query and
when <<Find>> button is pressed the filtered Select record sets return
to the form. Due to the number of fields and the complexity of the
drop down selection the query is well over 255 characters long so I
cannot enter the SQL statment to the RecordSource field in the form's
data property page.

So, how does one execute a parameter select query via VB and return
the result to the form that's passing the parameter? Is it possible?
Thanks!

Peter Doering <no****@doering.org> wrote in message news:<bo*************@ID-204768.news.uni-berlin.de>...
On 7 Nov 2003 10:57:31 -0800, Louis wrote:
SQLStr = "SELECT Request.RequestID, Request.ReqName, Request.ReqDesc
FROM Request"
DoCmd.RunSQL SQLStr
'Debug.Print SQLStr


DoCmd.RunSQL is used for action queries, starting with UPDATE, DELETE etc.
You need to assign the SQL statement to the form's record source:

another form:
Forms!YourFormName.RecordSource = SQLStr

your current form:
Me.RecordSource = SQLStr

HTH - Peter

Nov 12 '05 #3
"Louis" <lo*******@lycos.com> wrote in message
news:13**************************@posting.google.c om...
I knew if i posted a short question it wouldn't work. My fault.
Here's what i'm trying to do.

I have multiple drop down filters and based on the combination of the
drop down I want to pass that information to a parameter query and
when <<Find>> button is pressed the filtered Select record sets return
to the form. Due to the number of fields and the complexity of the
drop down selection the query is well over 255 characters long so I
cannot enter the SQL statment to the RecordSource field in the form's
data property page.

So, how does one execute a parameter select query via VB and return
the result to the form that's passing the parameter? Is it possible?
Thanks!


I don't know the answer to your question, but I "think" that it is possible
in Access 2000 and higher to do this using ADO. However; I did want to
point out that the RecordSource property of a form does not have a 255
character limit so you should be able to just assign the SQL string to that
property.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 12 '05 #4
On 7 Nov 2003 13:53:37 -0800, Louis wrote:
I knew if i posted a short question it wouldn't work. My fault.
Here's what i'm trying to do.

I have multiple drop down filters and based on the combination of the
drop down I want to pass that information to a parameter query and
when <<Find>> button is pressed the filtered Select record sets return
to the form. Due to the number of fields and the complexity of the
drop down selection the query is well over 255 characters long so I
cannot enter the SQL statment to the RecordSource field in the form's
data property page. ...


As Rick has pointed out already:

Max RecordSource/RowSource lengths on ...
A97: 2,048 char's
A2002: 32,750 char's

In case this is not sufficient you can always use a stored query, e.g. your
example:

"SELECT Request.RequestID, Request.ReqName, Request.ReqDesc FROM Request;"

and add the criteria like ...

Me.RecordSource = ""
CONDstr = "[MyField1]='" & Me!fldCond1 & "' " & _
" AND [MyField2]='" & Me!fldCond2 '... and so on

SQLstr = CurrentDb.QueryDefs("YourQuery").SQL
SQLstr = Left(SQLstr, Len(SQLstr) - 3) 'cut-off ; and CrLf
SQLstr = SQLstr & " WHERE " & CONDstr & 2;"

CurrentDb.QueryDefs("YourQuery").SQL = SQLstr
Me.RecordSource = "YourQuery"

(not tested)

HTH - Peter

--
No mails please.
Nov 12 '05 #5
I was just having a similar problem:
Run Time error reported that string exceeded max length for recordsource property.

I was building the string while assigning it to recordsource:
Me.RecordSource = sqlSELECTString & sqlWHEREstring

Fixed by changing it to two statements and assiging a single string to recordsource.

RSstring = sqlSELECTString & sqlWHEREstring
Me.RecordSource = RSstring

Hope this helps others passing this way.
Cheers,
S:)
Jul 13 '06 #6

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

Similar topics

0
by: Anand Natrajan | last post by:
Hi! I have a VB .NET client that is accessing an rpc/encoded service deployed in Axis 1.2. One of the operations, whoami, returns a string array. The server-side Java signature of this method is...
9
by: Bryan Bullard | last post by:
#include <cstring> #include <iostream> #include <string> std::string foo() { char buf; strcpy(buf, "this is a test.");
5
by: J Lake | last post by:
I am working on a simple orderform script to keep a running total, however I am encountering some errors. function CalculateTotal() { var order_total = 0 // Run through all the form fields...
1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
2
by: Jeroen | last post by:
Here's the situation. My program will be able to start with an argument (a path to a file) and then run a batch of commands in that file. So if an argument is provided to the main method, the...
5
by: Bob | last post by:
Hi, i'm not sure to understand how a value is returned from a function. Look at this code below about a simple function that compares a value with values 1 from 5. I thought: if the passed...
2
by: GaryDean | last post by:
The following command... string DebugString = System.Web.HttpContext.Current.Server.MapPath("App_Themes"); is executed from my ThemeManager.cs class in my App_code directory It returns......
0
by: Algobardo | last post by:
Good morning, this is the first time i write on this forum because i googled and i've seen related post with no solution. I will expose briefly the problem. I'm using c# 3.5 and i'm trying using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.