Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / October 2007

Tip: Looking for answers? Try searching our database.

Recordset Based on Select Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wahab - 02 Oct 2007 14:08 GMT
Hi
Im writing RS on Query to update records to new table but it gives me error,
can some one help me to write this recrod set pls.
dim db as DAO.Database
dim rst as DAO.Recordset
dim rTarget as DAO.Recordset

Set rst = CurrentDb.OpenRecordset("QryCustCurrTransactions",dbOpenDynaset)
Set rTarget = CurrentDb.OpenRecordset("LocalTB", dbOpenDynaset)

Do Until rst.EOF
           rTarget.AddNew
           rTarget!TrnDate = DateSerial(Year(rst!TrnDate),
Month(rst!TrnDate) + 1, 1 - 1)
           rTarget!CustomerID = rst!CustomerID
           rTarget!Debit = rst!DrKD
           rTarget!Credit = rst!CrKD
           rTarget.Update
       rst.MoveNext
   Loop
rst.Close
rTarget.Close

Thanks in advance
John Spencer - 02 Oct 2007 16:28 GMT
Try using the Db database object.  I suspect that using
currentdb().OpenRecordset means that rst and rTarget are both going out of
scope as soon as the line has finished executing.

By the way, it is helpful to tell people the exact error you are getting and
on which line it occurs.  Makes trouble-shooting a lot easier.

dim db as DAO.Database
dim rst as DAO.Recordset
dim rTarget as DAO.Recordset

Set db = CurrentDB()  '<<< -----

'Note the change in the next two lines currentdb to db
Set rst = db.OpenRecordset("QryCustCurrTransactions",dbOpenDynaset)
Set rTarget = db.OpenRecordset("LocalTB", dbOpenDynaset)

Do Until rst.EOF
           rTarget.AddNew
           rTarget!TrnDate = DateSerial(Year(rst!TrnDate),
Month(rst!TrnDate) + 1, 1 - 1)
           rTarget!CustomerID = rst!CustomerID
           rTarget!Debit = rst!DrKD
           rTarget!Credit = rst!CrKD
           rTarget.Update
       rst.MoveNext
   Loop
rst.Close
rTarget.Close

I would think you could do the same thing with an append query and it would
be more efficient

Dim StrSQL

StrSQL = "Insert into LocalTb(TrnDate, CustomerID, Debit, Credit)" & _
   " SELECT DateSerial(Year(TrnDate),Month(TrnDate),0)" & _
   ", CustomerID, DrKD, CrKD" & _
   "  FROM qryCustCurrTransactions"

CurrentDb().Execute StrSQL, DbFailonError

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Hi
> Im writing RS on Query to update records to new table but it gives me
[quoted text clipped - 21 lines]
>
> Thanks in advance
Dirk Goldgar - 02 Oct 2007 16:58 GMT
> Hi
> Im writing RS on Query to update records to new table but it gives me
[quoted text clipped - 21 lines]
>
> Thanks in advance

What error number and message are you getting?

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.