I am trying to add a data set via a form into a table using VBA. The code seems to work on other forms however it wont seem to work on this form.
The code works fine until it has to add the recordset (rst.AddNew)
Code is as follows:
Private Sub cmdAddtakings_Click()
On Error GoTo Err_Desc
'call the sub to do the add
Add_New_Takings Me.Name
Calc_FY_Totals "T", txtFY_End, Me.Name
Err_Exit:
Exit Sub
Err_Desc:
MsgBox Err.Number & Chr(13) & Err.Description, vbCritical, "Data Error"
Resume Err_Exit
End Sub
Sub Add_New_Takings(sFrmName)
Dim msg1 As String
Set rst = frm.RecordsetClone
rst.AddNew <------ Right here is gives the the error in the title
'rst(0) = IDNo
rst!TakingDate = frm!txt_TakingDate
rst!CashAmt = frm!txt_CashAmt
rst!EFT_Amt = frm!txt_EFT_Amt
rst.Update
rst.Close
frm.Requery
'clear the add variable
frm!txt_TakingDate = Date
frm!txt_CashAmt = Null
frm!txt_EFT_Amt = Null
frm!txt_total = 0
End Sub
PLEASE HELP!! Its driving me nuts,
Cheers!
DataChick
The code works fine until it has to add the recordset (rst.AddNew)
Code is as follows:
Private Sub cmdAddtakings_Click()
On Error GoTo Err_Desc
'call the sub to do the add
Add_New_Takings Me.Name
Calc_FY_Totals "T", txtFY_End, Me.Name
Err_Exit:
Exit Sub
Err_Desc:
MsgBox Err.Number & Chr(13) & Err.Description, vbCritical, "Data Error"
Resume Err_Exit
End Sub
Sub Add_New_Takings(sFrmName)
Dim msg1 As String
Set rst = frm.RecordsetClone
rst.AddNew <------ Right here is gives the the error in the title
'rst(0) = IDNo
rst!TakingDate = frm!txt_TakingDate
rst!CashAmt = frm!txt_CashAmt
rst!EFT_Amt = frm!txt_EFT_Amt
rst.Update
rst.Close
frm.Requery
'clear the add variable
frm!txt_TakingDate = Date
frm!txt_CashAmt = Null
frm!txt_EFT_Amt = Null
frm!txt_total = 0
End Sub
PLEASE HELP!! Its driving me nuts,
Cheers!
DataChick
Last edited: