Solved

Access vba search recordset for value

Posted on 2007-11-23
8
5,269 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…

737 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