R
Robert5833
Good day all,
“Back to the well†I come:
Disclaimer; I don’t know what I don’t know about programming…
I am trying to use the procedure below to append a group of records to a
table. I’m using a form to sort one table’s records on a unique value, and
display them in the form and I want that result (is it a recordset?) to
append to a different table with relevant fields. Call it an order fill list;
where I’ve selected all of the items I want, and then append them to an Order.
Throw the book at me; I’m open to criticism; as one has to be in the
learning process…<humble smile>
The code below does append to the target table; but only one record at a
time and it does compile without any snags:
Private Sub cmdLoadNew_Click()
On Error GoTo Error_Handler
Dim dbs As DAO.Database
Dim strSQL As String
Dim rst As DAO.Recordset
Set dbs = CurrentDb
With rst
strSQL = "INSERT INTO tblTracking, " _
& "([fldArticleID], " _
& "[fldMake], [fldModelNumber], [fldPartNumber]), " _
& "VALUES, " _
& "(' " & fldArticleID & " ', ' " & fldMake & " ', ' " & fldModelNumber
& "', " _
& " ' " & fldAircraftListID & " ')"
End With
CurrentDb.Execute strSQL, dbFailOnError
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
DisplayUnexpectedError Err.Number, Err.Description
Resume Exit_Procedure
Resume
End Sub
Note: single/double quotes exaggerated for clarity…
Note: the table that data is being appended FROM is tblArticleSelect...
I do have error handling but interestingly, if I include the “dbFailOnErrorâ€
with the Db.Execute strSQL statement it throws a flag; “Error Number 3464,
Data type mismatch in criteria expression†(which I am sure that has
something to do with data types) but otherwise, without that expression all
of the data is inserted anyway?
I’ve read every post on this subject I could find, and have used the Access
Help files, and my trusty “Access 2007 VBA Programmer’s Reference†guide, but
can’t find anything specific to my problem.
Also, I’ve had problems with calling global and public procedures as well;
with the errors; “Option not allowed or, Variable not defined.†I would
appreciate any input from the discussion group on that problem:
Example
Private Sub cmdLoadNew_Click()
Vs.
Public Function WinUserName() As String
Vs.
Public Function RoundCurr(OriginalValue As Currency, Optional
NumberOfDecimals As Integer) As Currency
I know there are differences between procedures and functions; I’m
particularly interested in what is within the (), or after (), and why?
Any help or suggestions would be greatly appreciated.
Best regards,
RL
“Back to the well†I come:
Disclaimer; I don’t know what I don’t know about programming…
I am trying to use the procedure below to append a group of records to a
table. I’m using a form to sort one table’s records on a unique value, and
display them in the form and I want that result (is it a recordset?) to
append to a different table with relevant fields. Call it an order fill list;
where I’ve selected all of the items I want, and then append them to an Order.
Throw the book at me; I’m open to criticism; as one has to be in the
learning process…<humble smile>
The code below does append to the target table; but only one record at a
time and it does compile without any snags:
Private Sub cmdLoadNew_Click()
On Error GoTo Error_Handler
Dim dbs As DAO.Database
Dim strSQL As String
Dim rst As DAO.Recordset
Set dbs = CurrentDb
With rst
strSQL = "INSERT INTO tblTracking, " _
& "([fldArticleID], " _
& "[fldMake], [fldModelNumber], [fldPartNumber]), " _
& "VALUES, " _
& "(' " & fldArticleID & " ', ' " & fldMake & " ', ' " & fldModelNumber
& "', " _
& " ' " & fldAircraftListID & " ')"
End With
CurrentDb.Execute strSQL, dbFailOnError
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
DisplayUnexpectedError Err.Number, Err.Description
Resume Exit_Procedure
Resume
End Sub
Note: single/double quotes exaggerated for clarity…
Note: the table that data is being appended FROM is tblArticleSelect...
I do have error handling but interestingly, if I include the “dbFailOnErrorâ€
with the Db.Execute strSQL statement it throws a flag; “Error Number 3464,
Data type mismatch in criteria expression†(which I am sure that has
something to do with data types) but otherwise, without that expression all
of the data is inserted anyway?
I’ve read every post on this subject I could find, and have used the Access
Help files, and my trusty “Access 2007 VBA Programmer’s Reference†guide, but
can’t find anything specific to my problem.
Also, I’ve had problems with calling global and public procedures as well;
with the errors; “Option not allowed or, Variable not defined.†I would
appreciate any input from the discussion group on that problem:
Example
Private Sub cmdLoadNew_Click()
Vs.
Public Function WinUserName() As String
Vs.
Public Function RoundCurr(OriginalValue As Currency, Optional
NumberOfDecimals As Integer) As Currency
I know there are differences between procedures and functions; I’m
particularly interested in what is within the (), or after (), and why?
Any help or suggestions would be greatly appreciated.
Best regards,
RL