Solved

VB module in access

Posted on 2000-05-17
5
159 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 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