By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Recordset RunSQL problem, please help.

P: 5

I'd really appreciate some help here people. I am trying to insert some values in a table in another database and not getting the results I am expecting. I am simply trying to insert values via a connection to a recordset and then close the recordset.

However I keep getting a type mismatch on the variable rstMainData.

Please can someone help me? The code is as below.

Private Sub txtGetURN_AfterUpdate()
DoCmd.SetWarnings False
Call ClearAll
Dim wsAccess As Workspace
Dim dbBackEnd As DAO.Database
Dim strSQL As String
Set wsAccess = DBEngine(0)

Set dbBackEnd = wsAccess.OpenDatabase("S:\RLR RMU\033 GI Services\NewParcelsCreated\ParcelsCreated_Data.mdb ", False, True)

MsgBox dbBackEnd.Name

Dim rstMainData As DAO.Recordset
Set rstMainData = dbBackEnd.OpenRecordset("tblMainData", dbOpenTable)

strSQL = "INSERT INTO tblMainDataNew SELECT tblMainData.* FROM "
strSQL = strSQL & rstMainData
strSQL = strSQL & " WHERE (((tblMainData.URN)=[Forms]![frmMainData]!txtGetURN]))"

Set rstMainData = Nothing

Set dbBackEnd = Nothing
DoCmd.SetWarnings True
Call RequeryLists

End Sub
Dec 10 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 2,653
Hi, Lazster.

Why pay more. You may append records from/to an external db table without getting connection to it.

to external db
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblMainDataNew IN 'S:\RLR RMU\033 GIServices\NewParcelsCreated\ParcelsCreated_Data.mdb' SELECT tblMainData.* FROM tblMainData WHERE (((tblMainData.URN)=[Forms]![frmMainData]!txtGetURN]));
from external db
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblMainDataNew SELECT tblMainData.* FROM tblMainData IN 'S:\RLR RMU\033 GIServices\NewParcelsCreated\ParcelsCreated_Data.mdb' WHERE (((tblMainData.URN)=[Forms]![frmMainData]!txtGetURN]));
Dec 10 '07 #2

Post your reply

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