karatelung
Registered User.
- Local time
- Today, 00:43
- Joined
- Apr 5, 2001
- Messages
- 84
i modified this code to suit my db (unsuccessfully) based on a db (MembershipV3A2K.mdb) that pat hartman posted in another thread. my intention is to be able to select multiple choices in a list box and append records with the click of a button.
here's the code:
when i click the command button, i get "3219 - invalid operation." i think this is because i have a field in the tblTraining (qryAddTraining is based on tblTraining) called AutoNumber which is an AutoNumber data type.
How do i modify the code to involve the AutoNumber? i assume that i'll have to include AutoNumber in qryAddTraining. do i need to add that field on the form as well?
if i can get this feature to work, it will save someone hours of work every time these need to be entered.
i've attached pat hartman's original db to avoid confusion.
thank you.
richie
here's the code:
Code:
Option Compare Database
Option Explicit
Private Sub cmdAddTraining_Click()
On Error GoTo Err_cmdAddTraining_Click
Me.txtNotice = CreateTrainingRecords(Me.List0)
Me.List0.Requery
Exit_cmdAddTraining_Click:
Exit Sub
Err_cmdAddTraining_Click:
MsgBox Err.Number & "-" & Err.Description
Resume Exit_cmdAddTraining_Click
End Sub
Public Function CreateTrainingRecords(ctlRef As ListBox) As String
On Error GoTo Err_CreateTrainingRecords_Click
Dim i As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qryAddTraining
Set rst = qd.OpenRecordset
For Each i In ctlRef.ItemsSelected
rst.AddNew
rst!IndFosterID = ctlRef.ItemData(i)
rst!DateTraining = Me.txtAddDate
rst!Title = Me.cmbAddTitle
rst!Code = Me.cmbAddCode
rst!Hrs = Me.txtAddHours
rst.Update
Next i
Set rst = Nothing
Set qd = Nothing
CreateTrainingRecords = "Records Created"
Exit_CreateTrainingRecords_Click:
Exit Function
Err_CreateTrainingRecords_Click:
Select Case Err.Number
Case 3022 'ignore duplicate keys
Resume Next
Case Else
MsgBox Err.Number & "-" & Err.Description
Resume Exit_CreateTrainingRecords_Click
End Select
End Function
when i click the command button, i get "3219 - invalid operation." i think this is because i have a field in the tblTraining (qryAddTraining is based on tblTraining) called AutoNumber which is an AutoNumber data type.
How do i modify the code to involve the AutoNumber? i assume that i'll have to include AutoNumber in qryAddTraining. do i need to add that field on the form as well?
if i can get this feature to work, it will save someone hours of work every time these need to be entered.
i've attached pat hartman's original db to avoid confusion.
thank you.
richie