473,657 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing dynamic sql to criteria field

Could someone please tell me how to pass criteria as if it were a parameter.

I have a routine now that creates the sql string (well almost). at present
the parameter is [Get DOS module] so I can pass one item ie Module M10S.
Want I want to do is send 1 or more parameters ie M10S OR M10SA OR ......

The query works with one parameter can I send the dynamic sql from vba as a
complete parameter string once the form calls the query?

also I notice the "air" code I have uses the hidden field of the list box ie
the PK is being returned can I get the descriptive text ie in my case
[Module description (text field)] "M10S" I couldnt see how to get the text
string from another column.

regards
Peter
Nov 13 '05 #1
3 4422
Hi Peter,

Please don't start a second thread if it's still related to the first. It
makes finding the answer to your original question easier.

To get the second column of a list box use
YourForm!YourLi stBox.ItemData( varItems).Colum n(1)
Column(0) is the first column (which is the default), Column(1) is the
second column, Column(2) is the third column, etc.

Use the dynamic sql string to create a query. Add a few more lines to the
code I posted earlier to create a query for the recordsource for your form.

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Set db = CurrentDB
*** The code posted earlier***
Set qdfTemp = db.CreateQueryD ef("YourQueryNa me", strSQL)

On Error Resume Next
Set qdf = Nothing
Set db = Nothing

Place all that code into the OnOpen event of your form.

You will need to write a good error trap routine to trap a zero record
recordset and if the query you're creating already exists.

In the OnClose event place this code
On Error Resume Next
DoCmd.DeleteObj ect acQuery, "Your Query Name"

Jeff
"Peter Bailey" <pe*********@an daluz.fsbusines s.co.uk> wrote in message
news:ch******** **@newsg2.svr.p ol.co.uk...
Could someone please tell me how to pass criteria as if it were a parameter.
I have a routine now that creates the sql string (well almost). at present
the parameter is [Get DOS module] so I can pass one item ie Module M10S.
Want I want to do is send 1 or more parameters ie M10S OR M10SA OR ......

The query works with one parameter can I send the dynamic sql from vba as a complete parameter string once the form calls the query?

also I notice the "air" code I have uses the hidden field of the list box ie the PK is being returned can I get the descriptive text ie in my case
[Module description (text field)] "M10S" I couldnt see how to get the text
string from another column.

regards
Peter

Nov 13 '05 #2
That was really bad nettiqette on my behalf, sorry for that Jeff and thank
you.

"Jeff Smith" <No***@Not.This .Address> wrote in message
news:ch******** **@news.wave.co .nz...
Hi Peter,

Please don't start a second thread if it's still related to the first. It
makes finding the answer to your original question easier.

To get the second column of a list box use
YourForm!YourLi stBox.ItemData( varItems).Colum n(1)
Column(0) is the first column (which is the default), Column(1) is the
second column, Column(2) is the third column, etc.

Use the dynamic sql string to create a query. Add a few more lines to the
code I posted earlier to create a query for the recordsource for your form.
Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Set db = CurrentDB
*** The code posted earlier***
Set qdfTemp = db.CreateQueryD ef("YourQueryNa me", strSQL)

On Error Resume Next
Set qdf = Nothing
Set db = Nothing

Place all that code into the OnOpen event of your form.

You will need to write a good error trap routine to trap a zero record
recordset and if the query you're creating already exists.

In the OnClose event place this code
On Error Resume Next
DoCmd.DeleteObj ect acQuery, "Your Query Name"

Jeff
"Peter Bailey" <pe*********@an daluz.fsbusines s.co.uk> wrote in message
news:ch******** **@newsg2.svr.p ol.co.uk...
Could someone please tell me how to pass criteria as if it were a parameter.

I have a routine now that creates the sql string (well almost). at present the parameter is [Get DOS module] so I can pass one item ie Module M10S.
Want I want to do is send 1 or more parameters ie M10S OR M10SA OR .......
The query works with one parameter can I send the dynamic sql from vba as a
complete parameter string once the form calls the query?

also I notice the "air" code I have uses the hidden field of the list
box ie
the PK is being returned can I get the descriptive text ie in my case
[Module description (text field)] "M10S" I couldnt see how to get the

text string from another column.

regards
Peter


Nov 13 '05 #3
My apologies AGAIN i thought I had tagged this to my original question! of
yesterday.

"Peter Bailey" <pe*********@an daluz.fsbusines s.co.uk> wrote in message
news:ch******** **@news7.svr.po l.co.uk...
The following code correctly creates the string and if I paste this into a
query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set querydefs
part of the code doesnt update the sql so I get the string from when it ran previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click( )

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DO SMBK.Date," & """d/m/yy" & """))" & " AS DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.Item sSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Colu mn(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qr ygetdosmodulebo okings") Then
Set qdfTemp = db.CreateQueryD ef("Qrygetdosmo dulebookings", strSQL)
DoCmd.OpenQuery "Qrygetdosmodul ebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Q rygetdosmoduleb ookings")
DoCmd.OpenQuery "Qrygetdosmodul ebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub

"Jeff Smith" <No***@Not.This .Address> wrote in message
news:ch******** **@news.wave.co .nz... Hi Peter,

Please don't start a second thread if it's still related to the first. It
makes finding the answer to your original question easier.

To get the second column of a list box use
YourForm!YourLi stBox.ItemData( varItems).Colum n(1)
Column(0) is the first column (which is the default), Column(1) is the
second column, Column(2) is the third column, etc.

Use the dynamic sql string to create a query. Add a few more lines to the
code I posted earlier to create a query for the recordsource for your form.
Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Set db = CurrentDB
*** The code posted earlier***
Set qdfTemp = db.CreateQueryD ef("YourQueryNa me", strSQL)

On Error Resume Next
Set qdf = Nothing
Set db = Nothing

Place all that code into the OnOpen event of your form.

You will need to write a good error trap routine to trap a zero record
recordset and if the query you're creating already exists.

In the OnClose event place this code
On Error Resume Next
DoCmd.DeleteObj ect acQuery, "Your Query Name"

Jeff
"Peter Bailey" <pe*********@an daluz.fsbusines s.co.uk> wrote in message
news:ch******** **@newsg2.svr.p ol.co.uk...
Could someone please tell me how to pass criteria as if it were a parameter.

I have a routine now that creates the sql string (well almost). at present the parameter is [Get DOS module] so I can pass one item ie Module M10S.
Want I want to do is send 1 or more parameters ie M10S OR M10SA OR .......
The query works with one parameter can I send the dynamic sql from vba as a
complete parameter string once the form calls the query?

also I notice the "air" code I have uses the hidden field of the list
box ie
the PK is being returned can I get the descriptive text ie in my case
[Module description (text field)] "M10S" I couldnt see how to get the

text string from another column.

regards
Peter


Nov 13 '05 #4

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

Similar topics

1
4595
by: Kevin Lyons | last post by:
Hello, I am trying to get all of my form elements passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html to the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing name, email, countries, cities, products, courses, etc. The others display as they should on the subsequent page,
7
3414
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password are input in login screen. The password in the database is a number field. I am writing the dynamic sql statement as follows below. I believe I am going wrong in the password section of the code. I appreciate any help. Thanks. Regards.
1
17657
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
0
3497
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
1
2820
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters in varying search criteria, hits "search", info is passed to a stored proc, results return and displayed in the datagrid. Every field in the datagrid is numeric (indicative of a certain sum or total) data but also functions as a...
2
2931
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic sub-report will capture what grades the student has achieved in a list of different subjects and the reason I need it to be dynamic is that students take different subjects. Basically I've been trying to doctor the KB article on dynamic
1
1457
by: Spanner77 | last post by:
Hi guys, I'm using Access 2002 and need to pass a parameter to a select query that will either return ALL records (including NULL values) OR exclude NULL values only, on a particular field. Put another way, I need to give the user the ability to set a particular field as follows: Criteria: 'Is Not Null' (return all records where the field value exclude null) OR Criteria: (return all records including where...
1
6985
by: Lacutas | last post by:
Hi I'm having some problems getting a dynamic LINQ query to work on my DataSet. The idea is that a user selects certain criteria, and then the LINQ query filters through the dataset making the requested changes. The table I am trying to alter is called RawData, this is defined in a DataSet but has no data columns as these aren't known until some data is imported. As part of my import routine it automatically creates the correct columns...
3
2749
by: RoadRunner | last post by:
Hi, I am having a problem. I have a very simple employee database. The client needs to see everything on a form before any updates or deletions can be made. I have a form that loads with two parameters (date range) a start date and a end date. I have two queries - Separation Update (adds to the separation table) and Separation Delete (deletes from the main table), they both run with the same parameters as the form. Is there a way that...
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.