In AC97, I get a syntax error with the following
I'm trying to insert a range of values into a table. I have frmAddNewTrainNo with tbxTrainYear, tbxTrainNoStart, and tbxTrainNoFinish. I would like to add records to tblTrain that has fields TrainID, TrainYear, and TrainNo. When the user enters a year and starting and ending train numbers, and hits the cmdAddRecord button, I'd like a record added for each TrainYear and TrainNo.
I'm not even sure if I'm using the best code.
Any suggestions?
Thanks,
Brian
Code:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click
DoCmd.SetWarnings True
Dim AddTrainNo As Variant, tbx1 As TextBox, tbx2 As TextBox, tbx3 As TextBox, SQL1 As String, DQ As String, itm As Variant
Set tbx1 = Me!tbxTrainNoStart
Set tbx2 = Me!tbxTrainNoFinish
Set tbx3 = Me!tbxTrainYear
DQ = """"
For AddTrainNo = Me!tbxTrainNoStart To Me!tbxTrainNoFinish
SQL1 = "INSERT INTO tblTrain (TrainYear,TrainNo) " & _
"VALUES( & DQ & tbx3.Value & DQ & "," _
" & DQ & tbx1.Value & DQ & ");"
Debug.Print SQL1
DoCmd.RunSQL SQL1
Set Me!tbxTrainNoStart = Me!tbxTrainNoStart + 1
Next
Set tbx1 = Nothing
Set tbx2 = Nothing
Set tbx3 = Nothing
Exit_cmdAddRecord_Click:
Exit Sub
Err_cmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecord_Click
End Sub
I'm trying to insert a range of values into a table. I have frmAddNewTrainNo with tbxTrainYear, tbxTrainNoStart, and tbxTrainNoFinish. I would like to add records to tblTrain that has fields TrainID, TrainYear, and TrainNo. When the user enters a year and starting and ending train numbers, and hits the cmdAddRecord button, I'd like a record added for each TrainYear and TrainNo.
I'm not even sure if I'm using the best code.
Any suggestions?
Thanks,
Brian