Solved

Access vba search recordset for value

Posted on 2007-11-23
8
5,265 Views
Last Modified: 2012-05-05
I have a table that has a recordsource with 3 tables in it. This form has a button on it and the button creates records in another table. I am having a problem searching through the recordset for the record I am currently editing. Please see code below and tell me where im going wrong. Thanks
Dim strQty, strRecord, strAssetID, strOtherID As String
Dim strDesc, strCategory, strPO As String
Dim RS As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim NRecords As Long
 
Set RS = Me.[tblOrders subform].Form.RecordsetClone
Set rs2 = CurrentDb.OpenRecordset("tblOrders")
strCategory = Forms!frmPur![Orders subform].Form!CatID
 
strRecord = RS.RecordCount
 
RS.MoveFirst
While Not RS.EOF
	strDesc = Forms!frmPur![Orders subform].Form!Description
	strQty = RS.Fields!Unit_Quantity
	strPO = Me.PO__
	
rs2.FindNext "Item_ID = " & strop       <Ÿ--running into error here.
strAssetID = rs2.Fields(0).Value
	
	Do While strQty <> NRecords
	NRecords = DCount("*", "tblAssets", "[Item_ID] = " & strAssetID)
		
		If strCategory = "5" Or strCategory = "6" Then
			Dim theSQL
	theSQL = ("UPDATE tblAssets SET tblAssets.Software_Num = " & [Forms]![frmPurchases]![Text16])  '"SW-"')
 
	theSQL = theSQL & " WHERE tblAssets.Item_ID LIKE '" & strAssetID & "'
 
	CurrentDb.Execute theSQL
End If
	RS.MoveNext
Wend

Open in new window

0
Comment
Question by:onesaint
8 Comments
 
LVL 3

Expert Comment

by:jlaborde
ID: 20341265
onesaint,

It looks like you transposed the strPO into strop in the line that is erroring.

0
 

Author Comment

by:onesaint
ID: 20341269
er, sorry.

I have a Form with a subform on it. there is a  button on the parent form that i would like to creates records in another table (one of 3 record sources in the parent form, but not the source of ths subform). I am having a problem searching through the recordset of the other table for the records corresponding to the parent form.  Please see code below and tell me where im going wrong. Thanks
0
 

Author Comment

by:onesaint
ID: 20341276
hmm its a typo. the error im getting is "operation is not supported by this type of object" corresponding to that line.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:onesaint
ID: 20341356
so i thought maybe i would try something like this:

Do
    If strPO = rs2.Fields(1).Value Then
    'code
    Else
    rs2.MoveNext
    End If
Loop Until rs2.EOF

but the value can match multiple times and im not sure how to dictate "koop until last match in the code".
0
 
LVL 17

Expert Comment

by:ramrom
ID: 20341533
rs2.findlast ?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 20341744
onesaint,

A little code cleanup is in order here:

Line 1:
Dim strQty, strRecord, strAssetID, strOtherID As String

In the above line of code, ONLY the *strOtherID* variable is ACTUALLY a String, all the others are VARIANTS.
I prefer this:
Dim strQty As String
Dim strRecordAs String
Dim strAssetIDAs String
Dim strOtherID As String

The same change is in order for line 2:
Change:
Dim strDesc, strCategory, strPO As String
To:
Dim strDesc  As String
Dim strCategory As String
Dim strPO As String

It may or may not make any difference with your error, but at least the variables will be correctly declared, and the code will be easier to read.

JeffCoachman
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 20341803
onesaint,

Try this:
rs2.FindNext "Item_ID = " & "'" & strPO &"'"
(Paste the above line of code into a MS Word Doc, to see it better)

It is hard to see here but, after your last  &  symbol is:
DoubleQuotesCharacter,SingelQuoteCharacter,DoubleQuotesCharacter & strPO & DoubleQuotesCharacter,SingelQuoteCharacter,DoubleQuotesCharacter

Also make sure none of the values you are assigning from...
    Forms!frmPur![Orders subform].Form!Description
    RS.Fields!Unit_Quantity
    strPO = Me.PO__
...contains a NULL

JeffCoachman

0
 

Author Closing Comment

by:onesaint
ID: 31410723
With boags assistance i was able to figure out the code.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question