Item not found -table name issue

P

Pele

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
first line of the code below; a message pops up and says "Item not found". I
am convnced it has to do with the spaces in the name of the table referred to
in the code. Can somebody tell me how to use a table name that has spaces in
a code. It is not an option for me to change the table name; I have to find a
way to let the code recognize the table name.

Pele



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
 
N

Nick via AccessMonster.com

Pele,

The way you have entered the table is correct.

Try just copying the table name from the database window and pasting it
between the
quotation marks. I've found that sometimes I might put two spaces where I
meant to
put one, and many times I can't notice unless I find the double spacing in
the VB editor.

If the above suggestion does not work, does the table reside in the current
database or is it being linked from another database? And how have you
declared 'rst'?

Hopefully it is a simple fix, if not then maybe we can get to the bottom of
this.

Nick
 
P

Pele

Nick,

Thanks for taking the time to take a look at this question. I copied and
pasted the name of the table and it still did not work. Anyway, below is the
complete code that somebody had given me. Let me know what you can find.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top