Solved

VB module in access

Posted on 2000-05-17
5
150 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 100 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

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

932 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

13 Experts available now in Live!

Get 1:1 Help Now