Solved

Access vba search recordset for value

Posted on 2007-11-23
8
5,274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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