Passing Value Of Recordset Into Where Clause

Oct 17, 2004

Hello! First time post, and I'm desperate for some help.

I am trying to use a loop through a recordset, pass the value of the current record into a WHERE
clause, run an append query based on the value of that record THEN loop through the recordset, pick the
next value, pass it to the WHERE clause, run the append, etc. I finally figured out how to set a variable as a
parameter for my WHERE clause and how to loop through a recordset.

My problem is this, I cannot get the variable (myvar) to update with the next value from the next record in
the recordset. My code loops through all records just fine, but it only appends the query result based on the
value of the first record. In short, I get 134 appended records all with the same value because myvar
never changes.

My code looks like this:

Public Sub OpeningARecordset()
Dim db As Database
Dim rec As Recordset
Dim myvar As Double
Set db = CurrentDb()
Set rec = db.OpenRecordset("Select SRS_SKU FROM tblUniqueSKUListing")
myvar = rec("SRS_SKU")
rec.OpenRecordset
Do Until rec.EOF
rec.MoveFirst
DoCmd.RunSQL ("INSERT INTO [Loc Group Names] ( SRS_LOCGROUP, [Loc Group] )" _
& " SELECT tblUniqueSKUListing.SRS_SKU, tblUniqueSKUListing.SM_DESC" _
& " FROM tblUniqueSKUListing WHERE (((SRS_SKU)=" & myvar & "));")
rec.MoveNext
Loop
rec.Close
End Sub

Can anyone shed some light on how I get myvar to update with the value of the next record once the append
is done?

Any help is extremely appreciated!!!

swenerst

View Replies


ADVERTISEMENT

Passing A Parameter For The Order By Clause

May 26, 2005

Can someone please tell me if it is possible to pass in a parameter for the sorting field to a stored procedure in MS Access.
When I tried to execute a query similar to below, neither did the query give me an error nor did it execute correctly.

PARAMETERS ORDERBY_FIELD as Text;
Select * from Employees Order By ORDERBY_FIELD;

It will be great if someone could help me with this.

Thanks.

View 1 Replies View Related

Modules & VBA :: Passing RecordSet As A Parameter

Sep 19, 2014

I'm trying to the following sub to automate the creation of RecordSets but I'm confuse how to get it done properly.

Public Sub OpenRecordSet(SQLString As String, NameRecordset As Object)
Set NameRecordset = New ADODB.Recordset
NameRecordset.Open SQLString, adOpenStatic, adLockOptimistic

I want to pass the name of the recordset as a parameter but I don't know how to set it.

View 1 Replies View Related

Modules & VBA :: Passing Recordset To Sub Procedure - Type Mismatch Error

Jul 13, 2015

I am trying to pass a recordset to a sub procedure as follows

Code:
Private Sub AddNewSProdStatus(rsTemp As DAO.Recordset)
rsSProdStatus.AddNew
rsSProdStatus![ProdID] = Me.Recordset![ProdStatusID]
rsSProdStatus![TitleID] = Me.Recordset![Title]
rsSProdStatus![ProdDealType] = 1

[Code] ....

However, whenever I call the procedure as below

Code:
AddNewSProdStatus (rsCSales)

I get a type mismatch error.

All Recordsets are declared as DAO and contain data...

View 1 Replies View Related

Modules & VBA :: How To Extract Recordset From Subform Into Recordset Object

Aug 14, 2015

Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.

The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.

The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.

The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.

Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?

Note: Immediate Window - One single field can be returned quickly

There are 48 fields that need validation - is there a way to reference the entire recordset?

Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource

Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value

Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229

View 4 Replies View Related

Does A Filtered Mdb Recordset Still Bring Down The Whole Recordset?

Apr 27, 2007

Hi guys, I'm a bit confused: I know that opening a bound form will bring down the whole recordset. But if I create a parametered query as the recordsource, will it still bring down the whole recordset first and only afterwards cut down to the records matching the parameters?

Example: I have a clients table with 5000 clients on a backend mdb, and my client lookup form in my frontend mdb. If I open the form looking for just client "Jim Jones" (via the parameter query), will Access bring down all 5000 clients from the backend to my frontend first, and only then seek out "Jim Jones" before discarding the rest of the recordset?

For if this is true then this whole Access business is rather unsuited for networks, even a small one. I hope you guys prove me wrong.

Premy

View 14 Replies View Related

Modules & VBA :: Can Use Result Of One Recordset For Other Recordset

Jul 7, 2013

I want to write a email where there are 2 or 3 different ordernumbers for same email, i want to include the email in the mail part as single column table. how to do it? also can i use result of one recordset for other recordset?

View 1 Replies View Related

Create A Recordset From A Recordset

Aug 17, 2007

from a table with fields userID and Date (in which any userID has multiple records with different Date values, and other fields) i have built a select query based on Date = one specific value. can anyone give an explanation (for beginners), through a sample code, that expands the query recordset so that the new recordset includes all records per userID that qualified in the prior recordset? below is an example. thank you!

Table with records:
userID / Date
u1 / d1
u1 / d2
u2 / d1
u2 / d2
u3 / d2
...
1st Select Query (where Date = d1):
u1 / d1
u2 / d1

Desired 2nd Query based off 1st Query (where ?):
u1 / d1
u1 / d2
u2 / d1
u2 / d2

View 3 Replies View Related

Updating One Recordset Using Another Recordset?

Jan 21, 2015

I have two tables that have the exact same fields. In table1 I have records that need to be UPDATED into table2. I tried an Update query and out of 600 records only half of those got updated. In my update query I joined tbl1 and tbl2 by Location (LOC) I checked for Nulls, Blanks, spaces, you name it. I can't figure why they all didn't get updated. I created a SQL query and go the exact same results. Ideally, I would like to create something in VBA to do this. I do not have any forms linked to these tables. In all I have about 600 records and 15 different fields that need to be updated. My example is only for one field.

sql example below. Which is the Access Sql in the Query

sql = "UPDATE tbl2 INNER JOIN tbl1 ON tbl2.LOC = tbl2.LOC" & _
"SET tbl2.Name = tbl1!Name" & _
"WHERE (((tbl2.Name) Is Null));"

Example.

Table1
Field1.Names = John

Table2
Field1.Names = "Need to UPDATE the name 'John' here"

I tried the Recordset .EDIT but I couldn't get it to work using two tables.

View 4 Replies View Related

Help With WHERE Clause

Oct 2, 2005

If this were a table

Amount Job_id Crew_id
$100 1 3
$200 2 4
$400 2 4
$600 2 3
$750 2 3
$800 3 7

and i needed a return (WHERE clause) when job_id is the same (i.e 2), and the crew_id is repeated like 4,4 and 33, how would i write it. I am trying to only sum the rows when this condition is fulfilled. Can anyoen help me

View 1 Replies View Related

Where Clause

May 29, 2006

Could anyone explain me the following sysntax :
... where ((cond1 and cond2) and (fld1<>'54')<>'60')
the syntax did not return any error while executing the query.

Thanks in adv.
nils

View 2 Replies View Related

Where Clause

Jul 26, 2006

I have an select statment that pulls data from a server. This server is really slow, and there is quite a bit of data. This statement has the following where clause.

"WHERE upc_number = '" & strPikWhere & "' AND ((dbo_root_description_type.description_name)='PFM S' Or " & _

"(dbo_root_description_type.description_name)='Full tech') AND ((dbo_root_price.zone) Not Like '8*') " & _

I was wondering if the order of these where statements would make a difference, and if so how?

View 1 Replies View Related

The Between Clause

Dec 5, 2006

Hi,

I have a query using the between clause with dates #01/01/2006# and #01/01/2007#. I have been reading a little on the between clause and it differs from SQL program to SQL program. What are its characteristics in MS Access is it >=#01/01/2006# AND <=#01/01/2007# or >=#01/01/2006# AND <#01/01/2007#.


Thank you.

View 4 Replies View Related

Where Clause

Feb 12, 2008

Where = "cardnumber = " & CardNumberGlobal

DoCmd.OpenForm "scoreform", acNormal, , Where, acFormAdd, acWindowNormal

When I do a Debug Print for where I get cardnumber = 1111111
The card number is a string because it might have a letter in it
don't i need it to be cardnumber = "1111111"

if so how do I get the quotes around the numbers

View 1 Replies View Related

Using An If Clause

Dec 1, 2004

I have a table "addresses" that has the following fields.......
id - type - street1 - street2

and type can be one of the follwoing
graduation,home,work

I am trying to write a query that gives the graduation address if it exists or if graduation doesnt exist it gives the home address.....
I was thinking of an If clause but do not know how to do it....
can i write a module...???
Any help on this is appreciated.....
Any other method also can be suggested....

View 1 Replies View Related

Calculated Value In Where Clause

Sep 30, 2005

In one of my queries, I'd like to reuse a calculated field as
criteria in the Where clause. SQL seems reluctant to want to
do this. You can RESTATE the calculation in the Where clause,
but can't refer to it by Name. You can Order by it, but it
can't be in the Where clause.

If the query result set consists on a set of Named columns, why
can you refer to a calculated column by Name in the "Order By"
clause but not in the Where clause?


Why is this OK?

Select FldA As FirstField,
FldB As SecondField,
FldA - FldB As TheDifference <-- Just a calculated field
From SomeTable

And this is OK?

Select FldA As FirstField,
FldB As SecondField,
FldA - FldB As TheDifference
From SomeTable
Order By TheDifference <-- Order By is OK

And this in not OK?

Select FldA As FirstField,
FldB As SecondField,
FldA - FldB As TheDifference
From SomeTable
Where TheDifference > 100 <-- Can't use TheDifference in Where clause

Don't want to repeat the calculation.

Select FldA As FirstField,
FldB As SecondField,
FldA - FldB As TheDifference
From SomeTable
Where FldA - FldB > 100 <-- I know this works, but ...
Order By TheDifference



Wayne

View 3 Replies View Related

Having Or Group Clause

Jun 2, 2006

i have to list BookID numbers borrowed by patrons where fine are greater than a set amount

View 1 Replies View Related

Searching With A Like Clause

Jul 12, 2007

hi, is it possible to have a form where you enter a word in a text box and it searchs a table and brings up all records which match it, but it doesnt have to be an exact match.

e.g.
you enter : the

results : the car
the bike
etc.

any help appreciated.

jjames

View 1 Replies View Related

Order By Clause Not Being Following

Jul 18, 2007

Hi

I have a problem with an Order By Clause.

Basically, my database holds records of sites in the UK, and I have a select query (qry_SumGIS3) that opens up a summary report (rptSumGIS3) when a button is clicked on the menu page. The report opens perfectly, showing me all the information I need to know about all the sites in my database. However, it is ignoring the Order By Clause I have specifically told it to do. I want to order the records that appear in the report by a calculated field (OBJ_WS_OVERALL_CALC) in descending order (highest to lowest percentage). Instead, it is ordering it by the site id (RTP_ID). How can I stop it doing this?

This is my code (that was created in the SQL view of the query design):
"SELECT MEASURE1.OBJ_WS_OVERALL_CALC, [Tab 1: Factual].RTP_ID, OBJECTIVES.OBJ_ID, OBJECTIVES.OBJ_NAME, MEASURE1.MEASURE_ID, MEASURE.MEASURE_NAME, MEASURE1.MEASURE_SCORE, MEASURE1.MEASURE_WEIGHT
FROM [Tab 1: Factual] INNER JOIN (OBJECTIVES INNER JOIN (MEASURE1 INNER JOIN MEASURE ON MEASURE1.MEASURE_ID = MEASURE.MEASURE_ID) ON OBJECTIVES.OBJ_ID = MEASURE.OBJ_ID) ON [Tab 1: Factual].RTP_ID = MEASURE1.RTP_ID
ORDER BY MEASURE1.OBJ_WS_OVERALL_CALC;"

The red line is the part of the code that I think is being ignored.

Anyone that can help me is a lifesaver!

View 1 Replies View Related

WHERE Clause In SQL String

Sep 3, 2007

Hi all, do you think you could help me with this SQL statement I'm using in vba code for a recordset object?

strSQL = "SELECT idCompactPartNumber, txtItem," & _
"lngDepartmentNumber , dteAquiredDate, curPrice," & _
"intQuantity , lngUnit, txtLocation," & _
"imgPicture, dteRetiredDate, blnActive," & _
"blnConsumables " & _
"FROM tblMaterials" & _
"WHERE lngDepartmentNumber=" & lngDepartment

When I try to open the recordset with this, it says there is an error in the WHERE clause. I've tried changing all sorts of things but nothing works. I've tried with the WHERE clause commented out and it all works fine then.

Hope you can help, thanks

View 5 Replies View Related

WHERE CLAUSE In SELECT

Oct 24, 2007

Hi Everyone,

I have the following SQL statement. The COUNT(b.BookingID) AS TB, gives me the number of bookings. I need to ensure that the number of bookings + PrebookCapacity is less than v.Capacity. I do this by:

COUNT(b.BookingID) AS TB + PrebookCapacity < v.Capacity in the WHERE CLAUSE. But when I run this in MS Access 2003, it says Enter Parameter Value for b.TB (It does not recognise b.TB as b.TB is not a table field). If I omit AND ((b.TB + PrebookCapacity < v.Capacity AND SessionStatus = 1) OR (b.TB < v.Capacity AND SessionStatus = 0)), from the WHERE clause, it works fine, also giving me the TB.

As I need to do my check in the WHERE clause, how can I check to make sure that the COUNT(b.BookingID) AS TB + PrebookCapacity is < v.Capacity, without any problems.

SELECT CourseName, Format([s.SessionDate]+[s.StartTime],"dd/mmm/yyyy hh:ss AM/PM") & " - " & Format([s.EndTime],"hh:ss AM/PM") AS [DateTime], s.SessionID, PrebookCapacity, v.Capacity,
COUNT(b.BookingID) AS TB
FROM tblCourses AS c, tblSessions AS s, tblVenues AS v, tblbookings AS b, qrySessionsAccepted AS q
WHERE c.CourseID = s.CourseID AND s.SessionID = 85 AND q.SessionID = s.SessionID AND b.SessionID = s.SessionID AND v.VenueID = s.VenueID
AND ((b.TB + PrebookCapacity < v.Capacity AND SessionStatus = 1) OR (b.TB < v.Capacity AND SessionStatus = 0))
GROUP BY CourseName, Format([s.SessionDate]+[s.StartTime],"dd/mmm/yyyy hh:ss AM/PM") & " - " & Format([s.EndTime],"hh:ss AM/PM"), s.SessionID, PrebookCapacity, v.Capacity;

Thanks,

Bash.

View 8 Replies View Related

Where Clause Issue

Dec 19, 2007

Hi I'm new to query writing and I'm needing help with a query that will search a field that either contains a name or an address and only return fields with addresses.

Select address1
From Booktable,
Where (Left([address1],1) = Like "[A-Z]"


Thanks in advance for any help!:D

View 2 Replies View Related

Parameter With IN Clause

Feb 7, 2008

in simple my query looks like

SELECT Field1, Field2
from table1
where table1.Field2 in (1,2,3)

and now i need to parameterize this query.... I tried with

SELECT Field1, Field2
from table1
where table1.Field2 in ([Parameter])

Now the problem is... it is working fine with only one value
For example if I input 1, it provide the required result. however, if I input 1,2 it doesnt provide a single recordset

I changed the datatype of parameter from number to text and also tried different way of inputting number like "1,2" , 1,2, but still problem is the same...

Can someone please guide me where I am going wrong

Thanks in advance

View 1 Replies View Related

Using Another Table In Where Clause

Feb 13, 2008

This probably sounds stupid but I need to ask because well, I'm stupid. I have created a separate table of partnumbers that DO NOT get included in a SELECT Query for another table (tblmain). How can I use this table in my WHERE clause? Below is my SQL statement and the table with the partnumbers is tblreportpartnumbers.

strSQL = "SELECT SUM([Yield]) AS [My Sum] FROM tblmain"
strSQL = strSQL & " WHERE(([Area]='Cell 1 Supfina' AND "
strSQL = strSQL & "([Date entered]=#" & dtmdate & "#"
strSQL = strSQL & " AND([Part Number]=???????)))"
strSQL = strSQL & " Group By [Date entered];"

Any help would be wonderfulllll

Thanks A lot

View 3 Replies View Related

Iif Statements... Then The WHERE Clause? Help!

Apr 16, 2008

Hi,
here is my query which runs within the VB code...

queryString2 = ""
queryString2 = queryString2 & " INSERT INTO markup SELECT TOP 1 JDE_Customer_No AS [JDE Customer No],"
queryString2 = queryString2 & " Custom2.Customer_Name AS [Customer Name],"
queryString2 = queryString2 & " part.id AS Part,"
queryString2 = queryString2 & " price_factor.use_fixed_price AS [Use_fixed],"
queryString2 = queryString2 & " iif(Use_fixed =1,fixed_price_list.price,price_list.price) AS [Base Price],"
queryString2 = queryString2 & " iif(Use_fixed =1,price_factor.fixed_price_factor,price_factor.fa ctor) AS [Factor],"
queryString2 = queryString2 & " iif(Use_fixed =1,fixed_price_list.min_quantity,price_list.min_qu antity) AS [Price Break],"
queryString2 = queryString2 & " part_select.quantity AS [Quantity Required],"
queryString2 = queryString2 & " part.unit_id As [Unit],"
queryString2 = queryString2 & " iif(Use_fixed =1"
queryString2 = queryString2 & " ,(price_factor.fixed_price_factor*(fixed_price_lis t.price*FixedCurrencyConUKP.sterling_exchange_rate ))"
queryString2 = queryString2 & " ,(price_factor.factor *(price_list.price*CurrencyConUKP.sterling_exchang e_rate))) AS Price"
queryString2 = queryString2 & " FROM part_select, part, fixed_price_list, price_list, price_factor, Custom2, CurrencyConUKP, FixedCurrencyConUKP"
queryString2 = queryString2 & " WHERE part.id = part_select.part"
queryString2 = queryString2 & " AND price_list.part_id = part.id"
queryString2 = queryString2 & " AND fixed_price_list.part_id = part.id"
queryString2 = queryString2 & " AND Custom2.JDE_Price_Group=price_factor.customer_grou p"
queryString2 = queryString2 & " AND price_factor.part_group=part." & PriceGroup
queryString2 = queryString2 & " AND Custom2.Customer_Name = " & "'" & CustomerSelection & "'"
queryString2 = queryString2 & " AND price_list.min_quantity <= part_select.quantity "
queryString2 = queryString2 & " AND fixed_price_list.min_quantity <= part_select.quantity "
queryString2 = queryString2 & " AND part.id = " & "'" & select_part_rst!part & "'"
queryString2 = queryString2 & " AND part_select.quantity = " & select_part_rst!quantity
queryString2 = queryString2 & " ;"

It all works pretty much fine, however, the problem occurs because the iif statement tells the code to use either the fixed_price_list table or the price_list table depending on the value of Use_fixed. the iif works fine, its the WHERE clause. because the iif statements tell the query to look at one table or the other, the WHERE clause includes statements from both tables e.g.

queryString2 = queryString2 & " AND price_list.min_quantity <= part_select.quantity "
queryString2 = queryString2 & " AND fixed_price_list.min_quantity <= part_select.quantity "

but some parts dont have information within the fixed_price_list table, and thus are not being found in the results due to the WHERE clause. can anyone help?? i tried using a left join but it didnt work how i wanted. in a perfect world i would be able to include a iif statement in the where clause e.g.

queryString2 = queryString2 & " iif Use_fixed =1, AND price_list.min_quantity <= part_select.quantity, AND fixed_price_list.min_quantity <= part_select.quantity) "

can anyone help?

View 5 Replies View Related

Where Clause Trouble

Apr 22, 2008

OK I have code to make a where clause this is working fine. Now I have to add another piece of code to filter it even more, this is where I am having trouble

Code that works fine

'construct a where clause as required for the list box
'if the Manufactur box is blank then all games will show up on the list
If Mfg = "0" Then Mfg = "*"
If Denom <> "" Then where = "DenomFix LIKE '" & Denom & "*' AND "
If Mfg <> "" Then where = where & "MFRCode LIKE '" & Mfg & "' AND "
If Search <> "" Then where = where & "Description LIKE '*" & Search & "*' AND "
'this will filter the list with only the approved games
Dim Aprvd As String
Aprvd = "Approved"
If Me.AprrovedCheck = True Then where = where & "Approved LIKE'" & Aprvd & "' AND "

'remove the trailing "AND ", if it exists
If Right(where, 4) = "AND " Then where = Left(where, Len(where) - 4)
'and if there is any text in the where clause, add the word 'WHERE '
If where <> "" Then where = "WHERE " & where
'apply the SQL to the rowsource of the List box to Pick a game

Me.List8.RowSource = _
"SELECT Approved, ReelStops As [Corp ID], DenomFix as Denom, Description As Theme, Par, MaxCoins As [Max Coin], PayLines As [Pay Lines]" & _
"FROM MachineTypeQuery " & _
where & _
"ORDER BY Description;"

Now what I need to add code to make a where clause that says something like DVIA is greater then 0 (DVIA >0) but I want to do this by its self and add it back into the where clause

Example
Private Sub ApplyPropertyWhere()
If PropertyGlobal = "DVIA" Then PropertyWhereGlobal = "DVIA > 0"

I would then put a line of code in the where clause like this
'This will filter the list with only the property they are from
If Me.PropertyCheck = True Then where = where & PropertyWhereGlobal

Please Help me fix the "DVIA >0" Thanks

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved