Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB module in access

Posted on 2000-05-17
5
Medium Priority
?
174 Views
Last Modified: 2010-05-02
Hi. I have a module in access that parses some info from a text file and matches a SS# to participant data in a table, then places the new info in another table. Three fields are taken from the participant table and added to the new table. The first field is fine, and the name is transferred to the new table. Then I get an error "item not found in collection" for the other two fields. I know these fields exist in rsPar, but I can't figure out what I'm doing wrong. Below is the code involved. Thanks!!

Set db = OpenDatabase(TANF)
Set rs = db.OpenRecordset("Data Import", dbOpenDynaset)

TranCode = Mid$(ReadData, 1, 2)
SSN = Mid$(ReadData, 51, 9)
Amount = Mid$(ReadData, 60, 10)
Warrant = Mid$(ReadData, 70, 8)

strCriteria = "SELECT Name FROM Participant_Records WHERE Social_Security = '" & SSN & "'"

Set rsPar = db.OpenRecordset(strCriteria)


If rsPar.RecordCount < 1 Then
 rs.AddNew
 rs("Social_Security") = SSN
 rs("Amount") = Amount / 100
 rs("Tran_Code") = TranCode
 rs("Warrant") = Warrant
 rs.Update
Else

rs.AddNew
rs("Social_Security") = SSN
rs("Name") = rsPar![Name]
rs("Amount") = Amount / 100
rs("Tran_Code") = TranCode
rs("Warrant") = Warrant

'HERE IS WHERE THE ERROR MESSAGE STARTS:
  rs("Bank_Routing_Number") = rsPar![Bank_Routing_Number]
 
  rs("Bank_Account_Number") = rsPar![Bank_Account_Number]

rs.Update
End If
0
Comment
Question by:CinBro
5 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 2817572
strCriteria should be

strCriteria = "SELECT Name, Bank_Routing_Number FROM Participant_Records WHERE Social_Security = '" & SSN & "'"



0
 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 2817577
sorry...

"SELECT Name, Bank_Routing_Number, Bank_Account_Number FROM Participant_Records WHERE Social_Security = '" & SSN & "'"



0
 
LVL 13

Expert Comment

by:crazyman
ID: 2817612
PaulHews is correct when you create the record set it's collection only contains the items that you have requested in the sql, you could just do a select * if you want every column or do as paul suggested to select particual colums.
0
 

Author Comment

by:CinBro
ID: 2817741
Thanks! I kept overlooking that and it was driving me crazy!!!!
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2817768
The RecordCount property doesn't indicate how many records are contained in a dbOpenDynaset Recordset object until all records have been accessed. Once the last record has been accessed, the RecordCount property indicates the total number of undeleted records in the Recordset or TableDef object. To force the last record to be accessed, use the MoveLast method on the Recordset object.. Eg.

Set rsPar = db.OpenRecordset(strCriteria)

rsPar.MoveLast

If rsPar.RecordCount < 1 Then
 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

927 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