Solved

Access vba search recordset for value

Posted on 2007-11-23
8
5,255 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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

14 Experts available now in Live!

Get 1:1 Help Now