Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB module in access

Posted on 2000-05-17
5
Medium Priority
?
169 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

671 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