Hello all,
I'm fairly new to programming vba in Access so please forgive my simple tries and help me understand what I'm doing wrong.
What I want to have happen when I click the "button", is for it to loop through each 'Code' in the 'Type of Training' table and enter the specified information from the current form into the 'tblTrainingDates' table.
The vba code inside my loop works because I've switched out 'fld' for the actual "Training Code" and it works fine. However, when I run it through the FOR EACH loop, I get the Runtime Error 3251: Operation is not supported for this type of object. The error falls on line: 'For Each fld In tdf'
I've also tried a DO WHILE loop and that doesn't work either.
What am I doing wrong? Thanks for all your help!
Sub cmdAddNewEmployeeTraining_Click()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb()
Set tdf = db.TableDefs("Type of Training")
Set fld = tdf.Fields("Code")
For Each fld In tdf
'Do While fld.Value <> ""
CurrentDb.Execute "INSERT INTO tblTrainingDates ([Employee ID],
I'm fairly new to programming vba in Access so please forgive my simple tries and help me understand what I'm doing wrong.
What I want to have happen when I click the "button", is for it to loop through each 'Code' in the 'Type of Training' table and enter the specified information from the current form into the 'tblTrainingDates' table.
The vba code inside my loop works because I've switched out 'fld' for the actual "Training Code" and it works fine. However, when I run it through the FOR EACH loop, I get the Runtime Error 3251: Operation is not supported for this type of object. The error falls on line: 'For Each fld In tdf'
I've also tried a DO WHILE loop and that doesn't work either.
What am I doing wrong? Thanks for all your help!
Sub cmdAddNewEmployeeTraining_Click()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb()
Set tdf = db.TableDefs("Type of Training")
Set fld = tdf.Fields("Code")
For Each fld In tdf
'Do While fld.Value <> ""
CurrentDb.Execute "INSERT INTO tblTrainingDates ([Employee ID],
Code:
,[Date Effective]) VALUES (" & Me.txtEmployeeID & ",'fld','""')"
Next
'Loop Until IsEmpty(fld)
End Sub
Last edited: