megatronixs
Registered User.
- Local time
- Today, 12:54
- Joined
- Aug 17, 2012
- Messages
- 719
Hi all,
I'm running first a query on linked table that will create a recordset.
I need to get this into a local table, but the recordset that is returned, has 2 values (from 2 different fields) but I got stuck with this.
Where did I go wrong on the below code? the "values(rst1, rst2)" is wrong, just don't know how to do it.
Greetings.
I'm running first a query on linked table that will create a recordset.
I need to get this into a local table, but the recordset that is returned, has 2 values (from 2 different fields) but I got stuck with this.
Where did I go wrong on the below code? the "values(rst1, rst2)" is wrong, just don't know how to do it.
Code:
Private Sub btn_check_pro_Click()
Dim db As DAO.Database
Set db = CurrentDb
Dim from_date As String
Dim to_date As String
Dim branch As String
Dim account As String
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset
Dim StrSQL As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT pro_nr FROM tbl_batch_process_pro", dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
pro_nr_txt = rs![pro_nr]
If rs.EOF = True Then
Set rs = Nothing
Set db = Nothing
Exit Sub
End If
Set rst = db.OpenRecordset("SELECT BRANCH_NO, ACCOUNT_NO " & _
"FROM tbl_products_1 " & _
"WHERE CUSTOMER_ID = " & pro_nr_txt & " AND ACCOUNT_TYPE_CODE = ""83""; ", dbOpenDynaset)
If Not rst.EOF Then
StrSQL = "INSERT INTO tbl_batch_process_idr (branch, account) VALUES (rst1, rst2);"
DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True
End If
Set rst = Nothing
Set rst = db.OpenRecordset("SELECT BRANCH_NO, ACCOUNT_NO " & _
"FROM tbl_products_2 " & _
"WHERE CUSTOMER_ID = " & pro_nr_txt & " AND ACCOUNT_TYPE_CODE = ""83""; ", dbOpenDynaset)
If Not rst.EOF Then
StrSQL = "INSERT INTO tbl_batch_process_idr (branch, account) VALUES (rst1, rst2);"
DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rst = Nothing
Set db = Nothing
Form.Requery
Form.Refresh
MsgBox "Your fries are done!", vbInformation
Form.Requery
End Sub
Greetings.