473,659 Members | 3,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Criteria from a Form in Code

I have succussfully ran the code below from a module. The code runs
SQL update statements from a memo field in a table, called tblSQL. The
field [tblSQL]![CalledFromProc] (Line 11) allows you to filter out the
records in the SQL table, this way you can run only certain groups of
SQL's/records.

Here is the problem. I created a form with a combo box that will allow
you to pick from [tblSQL]![CalledFromProc]. Then pasted the code below
into On Click in the form. Form some reason the SQL statement is not
referencing back to the Combo Box. If I type the text of the field in,
for example " CalledFromProc= 'Batch One'",

Any suggestions?

'****CODE BEGIN****
1 Sub sSomeSubRoutine ()
2 Dim lodb As Database, strSQL As String
3 Dim loSQLRS As Recordset, lngCurrent As Long
4 Dim varTmp As Variant
5 Const cERR_GRACEFUL_E XIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmd SetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecord set("Select * from tblSQL where" _
11 & " CalledFromProc= Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequenc e=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_E XIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes (!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequenc e=" & lngCurrent
22 Loop
23 End With
Nov 12 '05 #1
1 1971
Sorry, my message was posted prematurely.

I have successfully run the code below from a module. The code runs
SQL update statements from a memo field in a table, called tblSQL.
The
field [tblSQL]![CalledFromProc] (Line 11) allows you to filter out
the
records in the SQL table, this way you can run only certain groups of
SQL's/records.

Here is the problem. I created a form with a combo box that will
allow
you to pick from [tblSQL]![CalledFromProc]. Then pasted the code
below
into On Click in the form. For some reason the SQL statement is not
referencing back to the Combo Box. If I type the text from
[tblSQL]![CalledFromProc], for example " CalledFromProc= 'Batch One'",
it works. My only guess it that my syntax in the SQL statement it
wrong.

Any suggestions?

'****CODE BEGIN****
1 Sub sSomeSubRoutine ()
2 Dim lodb As Database, strSQL As String
3 Dim loSQLRS As Recordset, lngCurrent As Long
4 Dim varTmp As Variant
5 Const cERR_GRACEFUL_E XIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmd SetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecord set("Select * from tblSQL where" _
11 & " CalledFromProc= Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequenc e=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_E XIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes (!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequenc e=" & lngCurrent
22 Loop
23 End With

jf***@rochester .rr.com (Jason) wrote in message news:<bb******* *************** ****@posting.go ogle.com>...
I have succussfully run the code below from a module. The code runs
SQL update statements from a memo field in a table, called tblSQL. The
field [tblSQL]![CalledFromProc] (Line 11) allows you to filter out the
records in the SQL table, this way you can run only certain groups of
SQL's/records.

Here is the problem. I created a form with a combo box that will allow
you to pick from [tblSQL]![CalledFromProc]. Then pasted the code below
into On Click in the form. For some reason the SQL statement is not
referencing back to the Combo Box. If I type the text of the field in,
for example " CalledFromProc= 'Batch One'", it works. My only guess it that my syntax in the SQL statement it wrong.

Any suggestions?

'****CODE BEGIN****
1 Sub sSomeSubRoutine ()
2 Dim lodb As Database, strSQL As String
3 Dim loSQLRS As Recordset, lngCurrent As Long
4 Dim varTmp As Variant
5 Const cERR_GRACEFUL_E XIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmd SetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecord set("Select * from tblSQL where" _
11 & " CalledFromProc= Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequenc e=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_E XIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes (!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequenc e=" & lngCurrent
22 Loop
23 End With

Nov 12 '05 #2

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

Similar topics

19
3534
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the user clicks on the first list box (lstCollege), it returns values in the second list box...
3
11063
by: pelcovits | last post by:
I am trying to set up an unbound form to enter report criteria. I've followed the MS Office Assistance document: "Create a form to enter report criteria" which describes how to enter data (such as dates) in a text box. This procedure works fine. However, I also need to enter data from a combo box and I cannot get this to work. On my form I've created an unbound combo box named "Name". In the query bound to the report I've entered the...
2
1716
by: JM | last post by:
Hello, I've created a Querydef in a Form_Load() sub. The form is a subform that no longer has linked child fields. The form is bound to this querydef. When I open the form, the fields are populated just fine. However, when I add a new record using the new record control at the bottom of the subform, it gets added with NULL for the two values that were in the original WHERE clause. For example, if my query was "SELECT batch, style,...
3
3294
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string values in it like... Between #12/1/2004# And #12/31/2004# - or - >= #6/10/2005# - or -
8
2957
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. Now, let's say the user wants to be able to send mailings to people who have various combinations of membership and non-membership in those groups. Here's a medium-complex example: (Knitting Group or Macrame Group) and Active Contact and Mailing...
4
4029
by: EJO | last post by:
In the query builder, I can create a query that will take a date/time as criteria, and the query finds the records: SELECT SRSrvcsEquip.Stock, SRSrvcsEquip.Activity, SRSrvcsEquip.EquipOwned, SRSrvcsEquip.Manufacturer, SRSrvcsEquip.EHSN, SRSrvcsEquip.Qty, SRSrvcsEquip.PartNumber, SRSrvcsEquip.Description, SRSrvcsEquip.ListType, SRSrvcsEquip.Site_ID, SRSrvcsEquip.SR_ID, SRSrvcsEquip.ListDate, SRSrvcsEquip.ID FROM SRSrvcsEquip WHERE...
2
4229
by: rinmanb70 | last post by:
I have a QBF form/query and a report from the QBF that shows the results of the QBF. I would like to show the criteria on the report that was used in the QBF to get the info on report. I can't find how to do this except to show the "hard for users to understand" SQL WHERE statement. Anyone have a better way?
49
5991
by: martin DH | last post by:
Hello all, I'm back with another SQL related problem. The details are below, but in short: I am using Access 2003. I have a table whose structure may include four different associate names per record (full structure below). I have a query that should return records that have one or more entered names (as criteria from a form) belonging to them. TableName=COMPILE_HIST CompileID, autonumber, PK ResultsID, number Month, number, FK...
2
2111
by: Coll | last post by:
I have a form and a query. I would like to have some control on the form (check box probably), that when selected will limit the criteria for a field in a query. Here are the details.... When the checkbox (or whatever control is appropriate on the form) is checked, the field "employment_category" in my query will have the following criteria - not "temp" and not "diem" - I've tried several things, but I can't seem to figure out how to...
7
12505
by: DeZZar | last post by:
Hi all, Unfortunately I am quite a novice with Access!! I've created a number of data bases for my work however becuase my skills are limited to really built in functionality and wizards my programs are not really user friendly. I have searched and searched and tried numerous times to get the following right to no avail - and I think its really becuase of my lack of understanding.
0
8337
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,...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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
7359
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
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.