Database engine cannot find table. Why not?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MLH

    Database engine cannot find table. Why not?

    The Microsoft Jt database engine can not find
    tblJobSites, error #3078. That's what I get when
    executing this code...

    Private Sub Command1_Click( )
    Dim MyWorkspace As Workspace
    Set MyWorkspace = DBEngine.Worksp aces(0)
    Dim MyDB As Database
    Dim MyQueryDef As QueryDef, MyRecSet As Recordset
    Dim MyPeriod As String, MyRand As Double
    Set MyDB = MyWorkspace.Dat abases(0)
    Set MyQueryDef = MyDB.CreateQuer yDef("")

    With MyQueryDef
    ' Create temporary QueryDef.
    .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
    Set MyRecSet = .OpenRecordset( )
    MyRecSet.MoveFi rst
    End With

    Debug reports the problematic line ...
    Set MyRecSet = .OpenRecordset( )

    What have I done wrong here?

    (frmProgrammerO nly, Command1 button click, deadpest.mdb)

  • Douglas J. Steele

    #2
    Re: Database engine cannot find table. Why not?

    I hate to ask the obvious, but do you have a table named tblJobsites? Might
    it actually be tblJobsite or some other variation?

    --
    Doug Steele, Microsoft Access MVP

    (no e-mails, please!)



    "MLH" <CRCI@NorthStat e.net> wrote in message
    news:o75791dbbc o3pctlik3q0rb5q ha7t1krmm@4ax.c om...[color=blue]
    > The Microsoft Jt database engine can not find
    > tblJobSites, error #3078. That's what I get when
    > executing this code...
    >
    > Private Sub Command1_Click( )
    > Dim MyWorkspace As Workspace
    > Set MyWorkspace = DBEngine.Worksp aces(0)
    > Dim MyDB As Database
    > Dim MyQueryDef As QueryDef, MyRecSet As Recordset
    > Dim MyPeriod As String, MyRand As Double
    > Set MyDB = MyWorkspace.Dat abases(0)
    > Set MyQueryDef = MyDB.CreateQuer yDef("")
    >
    > With MyQueryDef
    > ' Create temporary QueryDef.
    > .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
    > Set MyRecSet = .OpenRecordset( )
    > MyRecSet.MoveFi rst
    > End With
    >
    > Debug reports the problematic line ...
    > Set MyRecSet = .OpenRecordset( )
    >
    > What have I done wrong here?
    >
    > (frmProgrammerO nly, Command1 button click, deadpest.mdb)
    >[/color]


    Comment

    • Br@dley

      #3
      Re: Database engine cannot find table. Why not?

      MLH <CRCI@NorthStat e.net> wrote:[color=blue]
      > The Microsoft Jt database engine can not find
      > tblJobSites, error #3078. That's what I get when
      > executing this code...
      >
      > Private Sub Command1_Click( )
      > Dim MyWorkspace As Workspace
      > Set MyWorkspace = DBEngine.Worksp aces(0)
      > Dim MyDB As Database
      > Dim MyQueryDef As QueryDef, MyRecSet As Recordset
      > Dim MyPeriod As String, MyRand As Double
      > Set MyDB = MyWorkspace.Dat abases(0)
      > Set MyQueryDef = MyDB.CreateQuer yDef("")
      >
      > With MyQueryDef
      > ' Create temporary QueryDef.
      > .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"[/color]

      ^^^

      Have you forgotten the ; character at the end of your SQL statement???

      [color=blue]
      > Set MyRecSet = .OpenRecordset( )
      > MyRecSet.MoveFi rst
      > End With
      >
      > Debug reports the problematic line ...
      > Set MyRecSet = .OpenRecordset( )
      >
      > What have I done wrong here?
      >
      > (frmProgrammerO nly, Command1 button click, deadpest.mdb)[/color]

      --
      regards,

      Bradley

      A Christian Response



      Comment

      • Douglas J. Steele

        #4
        Re: Database engine cannot find table. Why not?


        "Br@dley" <n0mail@4u.co m> wrote in message
        news:OVNke.38$B R4.6@news-server.bigpond. net.au...[color=blue]
        > MLH <CRCI@NorthStat e.net> wrote:
        > Have you forgotten the ; character at the end of your SQL statement???[/color]

        The semicolon isn't required.

        --
        Doug Steele, Microsoft Access MVP

        (no e-mails, please!)




        Comment

        • MLH

          #5
          Re: Database engine cannot find table. Why not?

          Its a fair Q. Yes, it has 604 records in it.
          I backed it up in the same dbase ==>
          tblJobsitesBAKU P.

          Comment

          • MLH

            #6
            Re: Database engine cannot find table. Why not?

            Have tried both with and without the semicolon.
            Same err rtnd either way.
            xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxx
            [color=blue]
            >
            >Have you forgotten the ; character at the end of your SQL statement???
            >
            >[color=green]
            >> Set MyRecSet = .OpenRecordset( )
            >> MyRecSet.MoveFi rst
            >> End With
            >>
            >> Debug reports the problematic line ...
            >> Set MyRecSet = .OpenRecordset( )
            >>
            >> What have I done wrong here?
            >>
            >> (frmProgrammerO nly, Command1 button click, deadpest.mdb)[/color][/color]

            Comment

            • MLH

              #7
              Re: Database engine cannot find table. Why not?

              The precise error message...

              Run-time error '3078':
              The Microsoft Jet database engine cannot find the input table or query
              'tblJobsites'. Make sure it exists and that its name is spelled
              correctly.

              I have copied the table to another table named 'a' and tried the same
              code again. It reports not being able to find 'a' as well. I have
              closed and reopened the database. Perhaps there's something
              wrong with my code syntax. I would appreciate you checking.

              Comment

              • MLH

                #8
                Re: Database engine cannot find table. Why not?

                Notice if I slightly change the SQL assignment to this...
                Private Sub Command1_Click( )
                Dim MyWS As Workspace
                Set MyWS = DBEngine.Worksp aces(0)
                Dim MyDB As Database
                Dim MyQD As QueryDef, MyRecSet As Recordset
                Dim MyPeriod As String, MyRand As Double
                Set MyDB = MyWS.Databases( 0)
                Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                WHERE [Period]='M';")

                With MyQD
                ' Create temporary QueryDef.
                ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                Set MyRecSet = .OpenRecordset 'This line gave me prob -
                Access said it couldn't find tblJobsites. Why?
                MyRecSet.MoveFi rst
                End With

                You see where I rem'd out the .SQL assignment in the With clause?
                I put it in a few lines up - just before the With statement. Debog
                reports the exact same error, citing that line as the problematic
                line. How can the Set MyQD line fail??? I just don't understand.

                Comment

                • MLH

                  #9
                  Re: Database engine cannot find table. Why not?

                  Also, if I remove the square brackets from the Period fieldname in the
                  SQL statement, the error is different and occurs on a different
                  line...

                  Private Sub Command1_Click( )
                  Dim MyWS As Workspace
                  Set MyWS = DBEngine.Worksp aces(0)
                  Dim MyDB As Database
                  Dim MyQD As QueryDef, MyRecSet As Recordset
                  Dim MyPeriod As String, MyRand As Double
                  Set MyDB = MyWS.Databases( 0)
                  ' Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                  WHERE [Period]='M';")
                  Set MyQD = MyDB.CreateQuer yDef("SELECT Period FROM tblJobsites
                  WHERE Period='M';")

                  With MyQD
                  ' Create temporary QueryDef.
                  ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                  Set MyRecSet = .OpenRecordset 'This line gave me prob -
                  Access said it couldn't find tblJobsites. Why?
                  MyRecSet.MoveFi rst
                  End With


                  Runtime error 3067...
                  Query input must contain at least one table or query.

                  Debug reports this as the problematic line...
                  Set MyRecSet = .OpenRecordset

                  Comment

                  • MLH

                    #10
                    Re: Database engine cannot find table. Why not?

                    I compacted the database to db1.mdb and repaired it
                    successfully. Then I opened db1 and ran this code again...

                    Private Sub Command1_Click( )
                    Dim MyWS As Workspace
                    Set MyWS = DBEngine.Worksp aces(0)
                    Dim MyDB As Database
                    Dim MyQD As QueryDef, MyRecSet As Recordset
                    Dim MyPeriod As String, MyRand As Double
                    Set MyDB = MyWS.Databases( 0)
                    ' Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                    WHERE [Period]='M';")
                    Set MyQD = MyDB.CreateQuer yDef("SELECT Period FROM tblJobsites
                    WHERE Period='M';")

                    With MyQD
                    ' Create temporary QueryDef.
                    ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                    Set MyRecSet = .OpenRecordset 'This line gave me prob -
                    Access said it couldn't find tblJobsites. Why?
                    MyRecSet.MoveFi rst
                    End With


                    This time the error returned was different...
                    Run-time error 3012...
                    Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
                    exists.

                    Am I not exiting the Workspace? What's going on. If I stop & restart
                    Access, this error is not the first, but you can bet it'll be the
                    second if I run the code again in the same instance of Access.

                    Comment

                    • Jeff Smith

                      #11
                      Re: Database engine cannot find table. Why not?


                      "MLH" <CRCI@NorthStat e.net> wrote in message
                      news:nhf791t63r q4k568u12ltmubq bnthshkpg@4ax.c om...[color=blue]
                      > Notice if I slightly change the SQL assignment to this...
                      > Private Sub Command1_Click( )
                      > Dim MyWS As Workspace
                      > Set MyWS = DBEngine.Worksp aces(0)
                      > Dim MyDB As Database
                      > Dim MyQD As QueryDef, MyRecSet As Recordset
                      > Dim MyPeriod As String, MyRand As Double
                      > Set MyDB = MyWS.Databases( 0)
                      > Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                      > WHERE [Period]='M';")
                      >
                      > With MyQD
                      > ' Create temporary QueryDef.
                      > ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                      > Set MyRecSet = .OpenRecordset 'This line gave me prob -
                      > Access said it couldn't find tblJobsites. Why?
                      > MyRecSet.MoveFi rst
                      > End With
                      >
                      > You see where I rem'd out the .SQL assignment in the With clause?
                      > I put it in a few lines up - just before the With statement. Debog
                      > reports the exact same error, citing that line as the problematic
                      > line. How can the Set MyQD line fail??? I just don't understand.[/color]

                      The first part of the CreateQueryDef method is the name of the query being
                      created. Try
                      Set MyQD = MyDB.CreateQuer yDef("", "SELECT [Period] FROM tblJobsites WHERE
                      [Period]='M';") or

                      Set MyQD = MyDB.CreateQuer yDef("TempQuery 1", "SELECT [Period] FROM
                      tblJobsites WHERE [Period]='M';")
                      Remember this will add a new query under the queries collection in the
                      database window.

                      Also what are you trying to do with the newly created query? If you're just
                      going to loop through the records, try using a recordset instead.

                      Jeff



                      Comment

                      • MLH

                        #12
                        Re: Database engine cannot find table. Why not?

                        >Run-time error 3012...[color=blue]
                        >Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
                        >exists.[/color]

                        I am getting this error everytime I runt the code now. Even when
                        I reboot the PC, launch Access 97, open the database and run
                        the code for the first time in the new instance of Access.

                        Comment

                        • Br@dley

                          #13
                          Re: Database engine cannot find table. Why not?

                          MLH <CRCI@NorthStat e.net> wrote:[color=blue]
                          > Also, if I remove the square brackets from the Period fieldname in the
                          > SQL statement, the error is different and occurs on a different
                          > line...
                          >
                          > Private Sub Command1_Click( )
                          > Dim MyWS As Workspace
                          > Set MyWS = DBEngine.Worksp aces(0)
                          > Dim MyDB As Database
                          > Dim MyQD As QueryDef, MyRecSet As Recordset
                          > Dim MyPeriod As String, MyRand As Double
                          > Set MyDB = MyWS.Databases( 0)
                          > ' Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                          > WHERE [Period]='M';")
                          > Set MyQD = MyDB.CreateQuer yDef("SELECT Period FROM tblJobsites
                          > WHERE Period='M';")
                          >
                          > With MyQD
                          > ' Create temporary QueryDef.
                          > ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                          > Set MyRecSet = .OpenRecordset 'This line gave me prob -
                          > Access said it couldn't find tblJobsites. Why?
                          > MyRecSet.MoveFi rst
                          > End With
                          >
                          >
                          > Runtime error 3067...
                          > Query input must contain at least one table or query.
                          >
                          > Debug reports this as the problematic line...
                          > Set MyRecSet = .OpenRecordset[/color]

                          Did you bother to check the Access help? A quick look showed your syntax
                          problem.. you need to specifiy an empty string as the QueryDef name.

                          This should work...

                          Dim MyWS As Workspace
                          Set MyWS = DBEngine.Worksp aces(0)
                          Dim MyDB As Database
                          Dim MyQD As QueryDef, MyRecSet As Recordset
                          Dim MyPeriod As String, MyRand As Double
                          Set MyDB = MyWS.Databases( 0)
                          Set MyQD = MyDB .CreateQueryDef ("")
                          With MyQD
                          .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
                          Set MyRecSet = .OpenRecordset( )
                          MyRecSet.MoveFi rst
                          End With

                          OR

                          Dim MyWS As Workspace
                          Set MyWS = DBEngine.Worksp aces(0)
                          Dim MyDB As Database
                          Dim MyQD As QueryDef, MyRecSet As Recordset
                          Dim MyPeriod As String, MyRand As Double
                          Set MyDB = MyWS.Databases( 0)
                          Set MyQD = MyDB .CreateQueryDef ("", SELECT [Period] FROM tblJobsites
                          WHERE [Period]='M')
                          With MyQD
                          Set MyRecSet = .OpenRecordset( )
                          MyRecSet.MoveFi rst
                          End With

                          --
                          regards,

                          Bradley

                          A Christian Response



                          Comment

                          • Br@dley

                            #14
                            Re: Database engine cannot find table. Why not?

                            MLH <CRCI@NorthStat e.net> wrote:[color=blue]
                            > I compacted the database to db1.mdb and repaired it
                            > successfully. Then I opened db1 and ran this code again...
                            >
                            > Private Sub Command1_Click( )
                            > Dim MyWS As Workspace
                            > Set MyWS = DBEngine.Worksp aces(0)
                            > Dim MyDB As Database
                            > Dim MyQD As QueryDef, MyRecSet As Recordset
                            > Dim MyPeriod As String, MyRand As Double
                            > Set MyDB = MyWS.Databases( 0)
                            > ' Set MyQD = MyDB.CreateQuer yDef("SELECT [Period] FROM tblJobsites
                            > WHERE [Period]='M';")
                            > Set MyQD = MyDB.CreateQuer yDef("SELECT Period FROM tblJobsites
                            > WHERE Period='M';")
                            >
                            > With MyQD
                            > ' Create temporary QueryDef.
                            > ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
                            > Set MyRecSet = .OpenRecordset 'This line gave me prob -
                            > Access said it couldn't find tblJobsites. Why?
                            > MyRecSet.MoveFi rst
                            > End With
                            >
                            >
                            > This time the error returned was different...
                            > Run-time error 3012...
                            > Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
                            > exists.
                            >
                            > Am I not exiting the Workspace? What's going on. If I stop & restart
                            > Access, this error is not the first, but you can bet it'll be the
                            > second if I run the code again in the same instance of Access.[/color]

                            Look under your Queries list... I suspect you've created a query named
                            "SELECT Period FROM tblJobsites WHERE Period="M';" !!!???

                            See my previous post.
                            --
                            regards,

                            Bradley

                            A Christian Response



                            Comment

                            • MLH

                              #15
                              Re: Database engine cannot find table. Why not?

                              Thanks Jeff. I have a hunch this'll work. BTW, all I'm gonna do is
                              loop through the records. I thought I needed to have a querydef
                              for that in DAO.

                              xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxx

                              On Wed, 25 May 2005 12:23:54 +1200, "Jeff Smith"
                              <NoSpam@Not.Thi s.Address> wrote:
                              [color=blue]
                              >Try
                              >Set MyQD = MyDB.CreateQuer yDef("", "SELECT [Period] FROM tblJobsites WHERE
                              >[Period]='M';") or
                              >
                              >Set MyQD = MyDB.CreateQuer yDef("TempQuery 1", "SELECT [Period] FROM
                              >tblJobsites WHERE [Period]='M';")
                              >Remember this will add a new query under the queries collection in the
                              >database window.
                              >
                              >Also what are you trying to do with the newly created query? If you're just
                              >going to loop through the records, try using a recordset instead.[/color]

                              Comment

                              Working...