P
Pele
I had posted this before but didn't get help.
Somebody had helped me put together a VB code to add some textboxes from a
form to a table. Anyway, I get an error message when the code reaches the
a point refering to OpenRecordset; a message pops up and says "Item not
found".
I don't know why the code can't find the table since it the table thus exist
and it is named correctly. Can somebody hep me with this code (see below); I
have to find a way to let the code recognize the table name; changing the
table name is not an option.
Below is the full code I am working with:
Pele
Private Sub CmdaddHeadCountRecord_Click()
On Error GoTo Err_CmdaddHeadCounTRecord_Click
Dim rst As DAO.Recordset
Dim SW As Integer
Dim EW As Integer
Dim totalrecords As Integer
Dim i As Integer
Dim varHDCT As Long
'check that data entry is complete and correct
If [Forms]![frm_add Head Count record]![test Entry] = 1 Then
DoCmd.RunMacro "Mac_check add Head count record entry"
Exit Sub
End If
'saves the record in table "HEAD COUNT TBL"
DoCmd.RunMacro "Mac_set CC Code in Head Count Table" 'to include CC
code in table
Me.Dirty = False
SW = Me.Start_Week 'Start_Week is the control
EW = Me.End_Week 'End_Week is the control
varHDCT = Me.hc_id ' HC_ID is a field
totalrecords = SW + EW + 1
' here is where you could put a message box asking
' if (EW-Sw+1) records should be created
'add records to table "HEAD COUNT EXTRA TIME TBL"
Set rst = CurrentDb.OpenRecordset("Head count extra time tbl")
With rst
For i = SW To EW
' Add new record.
.AddNew
!hc_id = varHDCT
!Week = i
![Meetings and training st] = Me.ST
'ub = unbound
![Meetings and training ot] = Me.OT
![Unscheduled OT] = Me.Unsched_OT
'save the record
.Update
Next
End With
'say how many records created
MsgBox EW - SW + 1 & " records added to table Head count extra time tbl"
Stop
Exit_CmdaddHeadCounTRecord_Click:
' clean up
rst.Close
Set rst = Nothing
'close the form
DoCmd.Close acForm, Me.Name
Exit Sub
Err_CmdaddHeadCounTRecord_Click:
MsgBox Err.Description
Resume Exit_CmdaddHeadCounTRecord_Click
End Sub
Somebody had helped me put together a VB code to add some textboxes from a
form to a table. Anyway, I get an error message when the code reaches the
a point refering to OpenRecordset; a message pops up and says "Item not
found".
I don't know why the code can't find the table since it the table thus exist
and it is named correctly. Can somebody hep me with this code (see below); I
have to find a way to let the code recognize the table name; changing the
table name is not an option.
Below is the full code I am working with:
Pele
Private Sub CmdaddHeadCountRecord_Click()
On Error GoTo Err_CmdaddHeadCounTRecord_Click
Dim rst As DAO.Recordset
Dim SW As Integer
Dim EW As Integer
Dim totalrecords As Integer
Dim i As Integer
Dim varHDCT As Long
'check that data entry is complete and correct
If [Forms]![frm_add Head Count record]![test Entry] = 1 Then
DoCmd.RunMacro "Mac_check add Head count record entry"
Exit Sub
End If
'saves the record in table "HEAD COUNT TBL"
DoCmd.RunMacro "Mac_set CC Code in Head Count Table" 'to include CC
code in table
Me.Dirty = False
SW = Me.Start_Week 'Start_Week is the control
EW = Me.End_Week 'End_Week is the control
varHDCT = Me.hc_id ' HC_ID is a field
totalrecords = SW + EW + 1
' here is where you could put a message box asking
' if (EW-Sw+1) records should be created
'add records to table "HEAD COUNT EXTRA TIME TBL"
Set rst = CurrentDb.OpenRecordset("Head count extra time tbl")
With rst
For i = SW To EW
' Add new record.
.AddNew
!hc_id = varHDCT
!Week = i
![Meetings and training st] = Me.ST
'ub = unbound
![Meetings and training ot] = Me.OT
![Unscheduled OT] = Me.Unsched_OT
'save the record
.Update
Next
End With
'say how many records created
MsgBox EW - SW + 1 & " records added to table Head count extra time tbl"
Stop
Exit_CmdaddHeadCounTRecord_Click:
' clean up
rst.Close
Set rst = Nothing
'close the form
DoCmd.Close acForm, Me.Name
Exit Sub
Err_CmdaddHeadCounTRecord_Click:
MsgBox Err.Description
Resume Exit_CmdaddHeadCounTRecord_Click
End Sub