473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problems Inserting information from one table to another

Would anyone know what exactly is causing the program to freeze when running this? Any tips on how i might get this to work would be appreciated too.

I am just trying to take information from one table and place it into another based on conditions. It is supposed to read and insert on a per row basis until it reaches EOF.



Private Sub Command2_Click()

Dim qdf As DAO.QueryDef
Dim recR As DAO.Recordset
Dim temp1 As String
Dim temp2 As String
Dim temp3 As String
Dim inv_number As String
Dim paid_amt As String
Dim bill_date As String



S = "SELECT Field1, Field2, Field3, Field4, Field5, Field6 FROM Table3 WHERE Table3.Field1='Bill Pmt -Check' Or Table3.Field1='Bill' Or Table3.Field1='Check'"


Dim cnn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cnn = CurrentProject.Connection
rs.Open S, cnn, adOpenDynamic

While Not rs.EOF

If rs("Field1") = "Bill Pmt -Check" Or rs("Field1") = "Bill" Then
temp1 = rs("Field2")
temp2 = rs("Field4")
temp3 = rs("Field3")

End If

If rs("Field1") = "Bill" Then
inv_number = rs("Field2")
paid_amt = rs("Field6")
bill_date = rs("Field3")
DoCmd.RunSQL "INSERT INTO WPR_labor serv_inv_num, asps_paid_station, asps_paid_station_date, asps_paid_station_date2, asps_paid_station_check VALUES ('" & inv_number & "', '" & paid_amt & "', '" & bill_date & "', '" & temp3 & "');"
End If

Wend
rs.Close
End Sub


Thanks ahead of time....
Mar 14 '07 #1
2 1373
ADezii
8,834 Expert 8TB
Would anyone know what exactly is causing the program to freeze when running this? Any tips on how i might get this to work would be appreciated too.

I am just trying to take information from one table and place it into another based on conditions. It is supposed to read and insert on a per row basis until it reaches EOF.



Private Sub Command2_Click()

Dim qdf As DAO.QueryDef
Dim recR As DAO.Recordset
Dim temp1 As String
Dim temp2 As String
Dim temp3 As String
Dim inv_number As String
Dim paid_amt As String
Dim bill_date As String



S = "SELECT Field1, Field2, Field3, Field4, Field5, Field6 FROM Table3 WHERE Table3.Field1='Bill Pmt -Check' Or Table3.Field1='Bill' Or Table3.Field1='Check'"


Dim cnn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cnn = CurrentProject.Connection
rs.Open S, cnn, adOpenDynamic

While Not rs.EOF

If rs("Field1") = "Bill Pmt -Check" Or rs("Field1") = "Bill" Then
temp1 = rs("Field2")
temp2 = rs("Field4")
temp3 = rs("Field3")

End If

If rs("Field1") = "Bill" Then
inv_number = rs("Field2")
paid_amt = rs("Field6")
bill_date = rs("Field3")
DoCmd.RunSQL "INSERT INTO WPR_labor serv_inv_num, asps_paid_station, asps_paid_station_date, asps_paid_station_date2, asps_paid_station_check VALUES ('" & inv_number & "', '" & paid_amt & "', '" & bill_date & "', '" & temp3 & "');"
End If

Wend
rs.Close
End Sub


Thanks ahead of time....
From my limited understanding, Jet does not support the use of Dynamic Cursors. Jet never delivers Dynamic type Recordsets but other data sources used from an Access database may such as an SQL Server Table. Simply replace the following and let me know how you made out.
Expand|Select|Wrap|Line Numbers
  1. rs.Open S, cnn, adOpenDynamic
-------------------------- replace with --------------------------
Expand|Select|Wrap|Line Numbers
  1. rs.Open S, cnn, adOpenKeyset
Mar 14 '07 #2
Run-time error '91':

Object variable of With block variable not set


This is the updated code:

Dim temp1 As String
Dim temp2 As String
Dim temp3 As String
Dim inv_number As String
Dim paid_amt As String
Dim bill_date As String



S = "SELECT Field1, Field2, Field3, Field4, Field5, Field6 FROM Table3 WHERE Table3.Field1='Bill Pmt -Check' Or Table3.Field1='Bill' Or Table3.Field1='Check'"


Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = CurrentProject.Connection
rs.Open S, cnn, adOpenKeyset

rs.Open S, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

While Not rs.EOF

If rs("Field1") = "Bill Pmt -Check" Or rs("Field1") = "Bill" Then
temp1 = rs("Field2")
temp2 = rs("Field4")
temp3 = rs("Field3")

End If

If rs("Field1") = "Bill" Then
inv_number = rs("Field2")
paid_amt = rs("Field6")
bill_date = rs("Field3")
DoCmd.RunSQL "INSERT INTO WPR_labor serv_inv_num, asps_paid_station, asps_paid_station_date, asps_paid_station_date2, asps_paid_station_check VALUES ('" & inv_number & "', '" & paid_amt & "', '" & bill_date & "', '" & temp3 & "', '" & temp1 & "');"
End If

Wend
rs.Close
Mar 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: simon | last post by:
Hi, I have two tables Table A = {ID, Item} Table B = {ID, IDA, subItem} Where ID auto increment. INSERT INTO TABLE_A ('items') values ('a')
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
3
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when...
4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
3
by: BNW | last post by:
Hi I'm trying to find a way in inserting a new row between an existing row in an Access Table just like an Excell Spreadsheet. The reason I need to know is because I have information in a table...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
5
LAD
by: LAD | last post by:
Using Access 2003 on Windows 2000. My Skill Level: Med Low (Some VBA, okay with Access) Form: Single View - based on Query of single Table to sort by field. Application: Dealers email 'contract...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.