473,473 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create 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_EXIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmdSetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecordset("Select * from tblSQL where" _
11 & " CalledFromProc=Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequence=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_EXIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes(!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequence=" & lngCurrent
22 Loop
23 End With
Nov 12 '05 #1
1 1960
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_EXIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmdSetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecordset("Select * from tblSQL where" _
11 & " CalledFromProc=Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequence=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_EXIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes(!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequence=" & lngCurrent
22 Loop
23 End With

jf***@rochester.rr.com (Jason) wrote in message news:<bb**************************@posting.google. 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_EXIT = vbObjectError + 20
6
7 On Local Error GoTo Err_handler
8 varTmp = SysCmd(acSysCmdSetStatus, "Starting Batch process...")
9 Set lodb = CurrentDb
10 Set loSQLRS = lodb.OpenRecordset("Select * from tblSQL where" _
11 & " CalledFromProc=Me![Combo1]",
12 dbOpenSnapshot)
13 lngCurrent = 1
14 With loSQLRS
15 .FindFirst "SQLSequence=" & lngCurrent
16 If .NoMatch Then Err.Raise cERR_GRACEFUL_EXIT
17 Do While Not .NoMatch
18 strSQL = adhHandleQuotes(!SQLString)
19 lodb.Execute strSQL, dbFailOnError
20 lngCurrent = lngCurrent + 1
21 .FindFirst "SQLSequence=" & 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
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...
3
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...
2
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...
3
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...
8
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. ...
4
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,...
2
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...
49
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...
2
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...
7
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...
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...
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...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.