473,395 Members | 1,675 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,395 software developers and data experts.

Final solution on copy a recordset?

Hi! I was a little too fast, because I had a new crash in what I
thought was a solution.
Then I discovered Allen Browne's webpage:
members.iinet.au/~allenbrowne, and found a
procedure I thought I could try. And now after testing and testing
and...it finally
seems to work! Don't ask me why. I moderated Allen's code a little
bit. :-)

Private Sub CopyRecordsetWithUnderlyingTablesToNewRecord_Click

Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim bInTrans As Boolean
Dim rs As DAO.Recordset
Dim sqlNew As String, strOnr As String
Dim lngNewOrderID As Long, lngKID As Long

On Error GoTo Err_COPY

Me.Refresh

lngKID = Me!CustID
strOnr = DMax("[Invoicenr]", "tblOrders") + 1
sqlNew = ""

Set ws = DBEngine(0)
ws.BeginTrans
bInTrans = True

Set db = ws(0)
Set rs = db.OpenRecordset("tblOrders", dbOpenTable)

rs.AddNew
rs!Invoicenr = strOnr
rs!CustID = lngKID
rs!MyDate = Date
rs!MyTime = Time
rs.Update
rs.Bookmark = rs.LastModified
lngNewOrderID = rs!InvoiceID

sqlNew = "INSERT INTO
tblOrderDetails(ItemID,Amount,Discount,Price,Fee,I nvoiceID) " & _
"SELECT ItemID,Amount,Discount,Price,Fee,," & lngNewOrderID & _
" FROM tblOrderDetails " & _
"WHERE InvoiceID = " & Me!InvoiceID

CurrentDb.Execute sqlNew, dbFailOnError

If MsgBox( _
"SURE U WILL COPY INVOICENR: " _
& Me!Invoicenr & "?", vbOKCancel, "COPY?") = vbOK Then

ws.CommitTrans
bInTrans = False
End If

rs.Close
db.Close
Set rs = Nothing
Set db = Nothing

'However in order to have the new added record show, I can't make it
show unless
'I do the following:

DoCmd.Close acForm, "frmOrders"

'Now open a splash screen for .500 sec
DoCmd.OpenForm "DESIGNER", acNormal
'And when the splash screen closes, it will call "frmOrders"
'Quite genious, huh?

Exit_COPY:
On Error Resume Next
Set rs = Nothing
Set db = Nothing
If bInTrans Then
ws.Rollback
End If
Set ws = Nothing

Exit Sub
Err_COPY:
MsgBox Err.Source & Chr(13) _
& Err.Number & " " & "ORDERS/COPY" & Chr(13) _
& Err.Description, vbCritical + vbOKOnly
Resume Exit_COPY
End Sub

Is there anybody out there that would dare to tell me what's going on?
Nov 13 '05 #1
0 1080

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: david | last post by:
Hi, I've been reading tons of posts on how to copy records, but to no avail....i'm still stuck. There are three tables: Main, Sub-Form1 & Sub-Form2 I have a form which displays some data....
4
by: Jim Devenish | last post by:
I wish to copy a table on a SQL Server backend to a table on an Access (.mdb) front end in the simplest way. I have the following to get the recordset but am seeking something easier. Dim...
2
by: mustang123 | last post by:
Hi, I get data from sybase server using ADO Connection and disconnected recordset in my access Database. Now I have a disconnected recordset. I want to insert the contents of this recordset...
0
by: Neelesh2007 | last post by:
Hi all, I have project with VB6.0 and Access-2003. I have datagrid and ADODC as datasource to retrieve records from database. To export the data of datagrid to Excel I am using Copy From Recordset...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.