PC Review


Reply
Thread Tools Rate Thread

Filtered Records as source for appending records to a table

 
 
8l2255
Guest
Posts: n/a
 
      7th Dec 2009
I have an inventory database with a form to create multiple items with the
same product information at once, it goes to a second form where the
individual serial numbers can be entered. The second form shows the filtered
recordset of items just created.

I want to be able to press a button on the second form and have a
transaction created in my transactiontbl using each of the itemids in the
filtered recordset.

The new transaction records should be as follows...

TransactionTbl
TransactionID -> Autonumber
Transdate -> Date ()
ItemID -> Number (foreign Key itemid from filtered recset)
UserID -> "15" (is always 15 on creation of a new item)
TransactionName -> "Initial Transaction"
Comments -> "" (can be left out - not filled out on new trans)
CurrentUser -> True (ticked checkbox)

The closest example had code similar to the following... my syntax in the
INSERT INTO or in VALUES appears to be very off!!

Private Sub Command35_Click()
Const NOCURRENTRECORD = 3021
Dim dbs As DAO.Database
Dim rst As Object
Dim lngItemID As Long
Dim strSQL As String
Set dbs = CurrentDb
Set rst = Me.Recordset.Clone
With rst
On Error Resume Next
.MoveFirst
Select Case Err.Number
Case 0
' no error
On Error GoTo 0
Do While Not .EOF
lngItemID = rst.Fields("ItemID")
strSQL = "INSERT INTO transactiontbl([ItemID], [TransDate],
[UserID], [TransactionName], [CurrentUser]) " & "VALUES( lngItemID ,
date(), 15 , 'Initial Transaction' , true )"
dbs.Execute strSQL
.MoveNext
Loop
Case NOCURRENTRECORD
MsgBox "No records match filter.", vbExclamation, "Warning"
Case Else
' unknown Error
MsgBox Err.Description, vbExclamation, "Error"
End Select
End With

End Sub


Any help welcome!

Thanks.

Lou
 
Reply With Quote
 
 
 
 
8l2255
Guest
Posts: n/a
 
      7th Dec 2009
Fixed my own problem (I think). Code is below.

Private Sub Command35_Click()
Const NOCURRENTRECORD = 3021
Dim dbs As DAO.Database
Dim rst As Object
Dim lngItemID As Long
Dim strSQL As String
Dim DQ As String

DQ = """"

Set dbs = CurrentDb
Set rst = Me.Recordset.Clone
With rst
On Error Resume Next
.MoveFirst
Select Case Err.Number
Case 0
' no error
On Error GoTo 0
Do While Not .EOF
lngItemID = rst.Fields("ItemID")
strSQL = "INSERT INTO transactiontbltest([ItemID], [TransDate],
[UserID], [TransactionName], [CurrentUser])" _
& "VALUES( " & DQ & lngItemID & DQ & " , " & DQ & Date & DQ & "
, 15 , 'Initial Transaction' , True);"
dbs.Execute strSQL


.MoveNext
Loop
Case NOCURRENTRECORD
MsgBox "No records match filter.", vbExclamation, "Warning"
Case Else
' unknown Error
MsgBox Err.Description, vbExclamation, "Error"
End Select
End With
DoCmd.close
End Sub

"8l2255" wrote:

> I have an inventory database with a form to create multiple items with the
> same product information at once, it goes to a second form where the
> individual serial numbers can be entered. The second form shows the filtered
> recordset of items just created.
>
> I want to be able to press a button on the second form and have a
> transaction created in my transactiontbl using each of the itemids in the
> filtered recordset.
>
> The new transaction records should be as follows...
>
> TransactionTbl
> TransactionID -> Autonumber
> Transdate -> Date ()
> ItemID -> Number (foreign Key itemid from filtered recset)
> UserID -> "15" (is always 15 on creation of a new item)
> TransactionName -> "Initial Transaction"
> Comments -> "" (can be left out - not filled out on new trans)
> CurrentUser -> True (ticked checkbox)
>
> The closest example had code similar to the following... my syntax in the
> INSERT INTO or in VALUES appears to be very off!!
>
> Private Sub Command35_Click()
> Const NOCURRENTRECORD = 3021
> Dim dbs As DAO.Database
> Dim rst As Object
> Dim lngItemID As Long
> Dim strSQL As String
> Set dbs = CurrentDb
> Set rst = Me.Recordset.Clone
> With rst
> On Error Resume Next
> .MoveFirst
> Select Case Err.Number
> Case 0
> ' no error
> On Error GoTo 0
> Do While Not .EOF
> lngItemID = rst.Fields("ItemID")
> strSQL = "INSERT INTO transactiontbl([ItemID], [TransDate],
> [UserID], [TransactionName], [CurrentUser]) " & "VALUES( lngItemID ,
> date(), 15 , 'Initial Transaction' , true )"
> dbs.Execute strSQL
> .MoveNext
> Loop
> Case NOCURRENTRECORD
> MsgBox "No records match filter.", vbExclamation, "Warning"
> Case Else
> ' unknown Error
> MsgBox Err.Description, vbExclamation, "Error"
> End Select
> End With
>
> End Sub
>
>
> Any help welcome!
>
> Thanks.
>
> Lou

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending Records from Table to Table Stephen sjw_ost Microsoft Access VBA Modules 1 12th Feb 2009 06:32 AM
Filtered records as source for appending records to a table LanceWilliams2418@sbcglobal.net Microsoft Access 3 16th May 2008 10:27 AM
Appending Overwriting, instead of appending =?Utf-8?B?QW5uZQ==?= Microsoft Access Queries 2 14th Feb 2007 07:05 PM
HELP!!!! Upload table records deletes existing records instead of appending. rbagley@kodersolutions.com Microsoft Dot NET Compact Framework 1 2nd Feb 2007 10:51 AM
HELP!!!! Upload table records deletes existing records instead of appending. rbagley@kodersolutions.com Microsoft Dot NET Compact Framework 0 2nd Feb 2007 03:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:10 PM.