Solved

VB module in access

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now