Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2005

Tip: Looking for answers? Try searching our database.

Table not found by code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pele - 29 Jul 2005 15:08 GMT
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
FSt1 - 29 Jul 2005 16:31 GMT
hi,
i think you have a naming  problem.
see this site.
http://support.microsoft.com/?id=826763
characters not to use with access.
Space in as the top of the list and your table name is full of spaces.
you might get it to go if you inclose your table name  in brackets [ name ]
but i would follow microsoft's advice and get rid of the spaces.

Post back if neither works.

Regards

FSt1

> I had posted this before but didn't get help.
>
[quoted text clipped - 78 lines]
>  
>  End Sub
Pele - 29 Jul 2005 18:47 GMT
FST1,

I don't have the option regarding the changing the name; I need to keep the
name as is and find a way around it. I tried the second proposal you made and
put the name in brackets. The problematic line now looks like this:

Set rst = CurrentDb.OpenRecordset("[Head count extra time tbl]", [Table])

Unfortunately, a window pops up and says "Microsoft Access can't find the
field 'forms' referred to in your expression". When I press okay, another
window pops up saying ""Object variable or with block variable not set". This
window seems to be locked in some kind of loop since it won't disappear after
i press OKay. Anyway, I can only get out by closing the application by using
the task manager.

Please let me know what other things I can try.

Toks

> hi,
> i think you have a naming  problem.
[quoted text clipped - 93 lines]
> >  
> >  End Sub
FSt1 - 29 Jul 2005 19:35 GMT
hi,
try this
add a dim
dim db as database
add a line
set db = codeDb()
Set rst = CurrentDb.OpenRecordset("[Head count extra time tbl]",dbOpenDynaset)

this is the same syntax i use with recordset that work. if this doesn't work
then something else is the problem. are you sure this is the line it is
crashing on?

post back if problems

regards

FSt1

> FST1,
>
[quoted text clipped - 112 lines]
> > >  
> > >  End Sub
Pele - 29 Jul 2005 21:36 GMT
Fst1,

I tried the additional code you'd provided and I got the following error
message:

The microsoft Jet database engine cannot find the input table or query
'[Head Count extra time tbl]'. Make sure it exists and that its name is spekt
correctly'.

I then took out the brackets from the name and reran it but it gave me the
eror message "Object variable or with block variable not set" and it then
gets stuck as before.

I know the line that is problematic because I put a msgbox before and after
that line and the msgbox before is the only one that gets displayed i.e. the
code stooped at that line. To make sure I didn't make a mistake in the name,
I copied the name from the table itself and it still didn't work.

Pele

> hi,
> try this
[quoted text clipped - 130 lines]
> > > >  
> > > >  End Sub
Pele - 29 Jul 2005 22:12 GMT
Fst1,

I apologize for this but your code was correct. I had made a mistake in the
name of one of my fields and that was the problem all along.

In the code below, I had been mistakenly using HC-ID instead of [HC ID].
Once I changed it, the code worked fine.

Thanks for your help.

Pele

Set rst = CurrentDb.OpenRecordset("Head count extra time tbl", dbOpenDynaset)
    '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

> hi,
> try this
[quoted text clipped - 130 lines]
> > > >  
> > > >  End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.