Solved

Access vba search recordset for value

Posted on 2007-11-23
8
5,260 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
 

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Runtime 2010 Error 17 33
Tags from access to excel 3 32
Track name AutoCorrect info 14 48
Acc 2010 pause execution 10 13
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

864 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now