Access Code Doesn't Work 
Author Message
 Access Code Doesn't Work

Help Please.

I've developed many applications in Access.  But I usually don't open databases and
recordsets using code.  Below is a very simple function (that will be expanded once I get
past this).  I borrowed the basic code from the Help File and just modified names of my
objects, etc.  For now, I put the code behind a form and call it OnClick of a Button..
What is wrong...

NOTE: I HAVE PUT THE ERRORS I GET INSIDE THIS COPY OF THE CODE (ALL UPPER CASE).
(They come from the TABLEERRORHANDLER section)
Function CONVERTtblVehicleMonthly ()

    CONVERTtblVehicleMonthly = True
    Const MB_ICONEXCLAMATION = 48
    Dim MyWorkspace As WorkSpace, MyDatabase As Database
    Dim MyFile As String
    Dim MyTable As Recordset
    Dim ErrorCondition As Integer
    ChDir "C:\DAR"
    MyFile = "C:\DAR\DARDATA.MDB"    ' Define name of database.

    On Error GoTo DBErrorHandler    ' Enable error trapping.

    If Not ErrorCondition Then
        On Error GoTo TableErrorHandler ' Enable error trapping.

        Set MyWorkspace = DBEngine.Workspaces(0)
        Set MyDatabase = MyWorkspace.OpenDatabase(MyFile)   ' Open database.
        Set MyTable = MyDatabase.OpenRecordset("tblVehicleMonthly")

        DoCmd SelectObject A_TABLE, "tblVehicleMonthly", True
1ST ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 2544 THAT SAYS NO
SUCH TABLE EXISTS.        
        MyDatabase.Close
2ND ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 3219 THAT SAYS I
HAVE PERFORMED AN ILLEGAL OPERATION.(PROBABLY BECAUSE THE DATABASE WAS NEVER OPENED??)

        Exit Function
    End If

    On Error GoTo 0 ' Disable error trapping.
    Exit Function

DBErrorHandler:
    ErrorCondition = True
    CONVERTtblVehicleMonthly = False
    MsgBox "Can't open DARDATA.MDB database.", MB_ICONEXCLAMATION
    Resume Next

TableErrorHandler:
    ErrorCondition = True
    CONVERTtblVehicleMonthly = False
    MsgBox Error$ & " " & Err MB_ICONEXCLAMATION
    Resume Next

EditErrorHandler:
    ErrorCondition = True
    CONVERTtblVehicleMonthly = False
    MsgBox "Can't edit Employees table.", MB_ICONEXCLAMATION
    Resume Next

End Function



Fri, 08 Oct 1999 03:00:00 GMT  
 Access Code Doesn't Work

BTW
OpenRecordset and SelectObject are very different and I wonder what you are
aiming to do (with the selected table).  Maybe this an example for our
benefit.

Do you understand what they are each doing?

'DoCmd SelectObject objecttype, objectname [, indatabasewindow]

SelectObject  is trying to select an object in the current database
(objects as listed in the DBC) , but your code looks as though it is trying
to open a recordset on a table in a different database.  That is why the
tabl is not found.

BTW, selecting an object in the database container window might fall over
in the run time version ( I am not sure).

HTH

--
Stephen Sarre
SIS
London UK



Quote:
> Help Please.

> I've developed many applications in Access.  But I usually don't open
databases and
> recordsets using code.  Below is a very simple function (that will be
expanded once I get
> past this).  I borrowed the basic code from the Help File and just

modified names of my
Quote:
> objects, etc.  For now, I put the code behind a form and call it OnClick
of a Button..
> What is wrong...

> NOTE: I HAVE PUT THE ERRORS I GET INSIDE THIS COPY OF THE CODE (ALL UPPER
CASE).
> (They come from the TABLEERRORHANDLER section)
> Function CONVERTtblVehicleMonthly ()

>     CONVERTtblVehicleMonthly = True
>     Const MB_ICONEXCLAMATION = 48
>     Dim MyWorkspace As WorkSpace, MyDatabase As Database
>     Dim MyFile As String
>     Dim MyTable As Recordset
>     Dim ErrorCondition As Integer
>     ChDir "C:\DAR"
>     MyFile = "C:\DAR\DARDATA.MDB"    ' Define name of database.

>     On Error GoTo DBErrorHandler    ' Enable error trapping.

>     If Not ErrorCondition Then
>         On Error GoTo TableErrorHandler ' Enable error trapping.

>         Set MyWorkspace = DBEngine.Workspaces(0)
>         Set MyDatabase = MyWorkspace.OpenDatabase(MyFile)   ' Open
database.
>         Set MyTable = MyDatabase.OpenRecordset("tblVehicleMonthly")

>         DoCmd SelectObject A_TABLE, "tblVehicleMonthly", True
> 1ST ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 2544
THAT SAYS NO
> SUCH TABLE EXISTS.        
>    MyDatabase.Close
> 2ND ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 3219
THAT SAYS I
> HAVE PERFORMED AN ILLEGAL OPERATION.(PROBABLY BECAUSE THE DATABASE WAS
NEVER OPENED??)

>         Exit Function
>     End If

>     On Error GoTo 0 ' Disable error trapping.
>     Exit Function

> DBErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox "Can't open DARDATA.MDB database.", MB_ICONEXCLAMATION
>     Resume Next

> TableErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox Error$ & " " & Err MB_ICONEXCLAMATION
>     Resume Next

> EditErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox "Can't edit Employees table.", MB_ICONEXCLAMATION
>     Resume Next

> End Function



Sun, 10 Oct 1999 03:00:00 GMT  
 Access Code Doesn't Work

First this appears to be Access-2, so I'll only guess the problem.
It appears that you have selected and object that is already open, but have
specified that you are selecting one that is in the database window only.
The illegal op is probably a result of this.
Try using false on the select object
Wally Burfine



Quote:
> Help Please.

> I've developed many applications in Access.  But I usually don't open
databases and
> recordsets using code.  Below is a very simple function (that will be
expanded once I get
> past this).  I borrowed the basic code from the Help File and just

modified names of my
Quote:
> objects, etc.  For now, I put the code behind a form and call it OnClick
of a Button..
> What is wrong...

> NOTE: I HAVE PUT THE ERRORS I GET INSIDE THIS COPY OF THE CODE (ALL UPPER
CASE).
> (They come from the TABLEERRORHANDLER section)
> Function CONVERTtblVehicleMonthly ()

>     CONVERTtblVehicleMonthly = True
>     Const MB_ICONEXCLAMATION = 48
>     Dim MyWorkspace As WorkSpace, MyDatabase As Database
>     Dim MyFile As String
>     Dim MyTable As Recordset
>     Dim ErrorCondition As Integer
>     ChDir "C:\DAR"
>     MyFile = "C:\DAR\DARDATA.MDB"    ' Define name of database.

>     On Error GoTo DBErrorHandler    ' Enable error trapping.

>     If Not ErrorCondition Then
>         On Error GoTo TableErrorHandler ' Enable error trapping.

>         Set MyWorkspace = DBEngine.Workspaces(0)
>         Set MyDatabase = MyWorkspace.OpenDatabase(MyFile)   ' Open
database.
>         Set MyTable = MyDatabase.OpenRecordset("tblVehicleMonthly")

>         DoCmd SelectObject A_TABLE, "tblVehicleMonthly", True
> 1ST ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 2544
THAT SAYS NO
> SUCH TABLE EXISTS.        
>    MyDatabase.Close
> 2ND ERROR COMES AFTER THE LINE ABOVE IS EXECUTED.  THE ERROR CODE IS 3219
THAT SAYS I
> HAVE PERFORMED AN ILLEGAL OPERATION.(PROBABLY BECAUSE THE DATABASE WAS
NEVER OPENED??)

>         Exit Function
>     End If

>     On Error GoTo 0 ' Disable error trapping.
>     Exit Function

> DBErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox "Can't open DARDATA.MDB database.", MB_ICONEXCLAMATION
>     Resume Next

> TableErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox Error$ & " " & Err MB_ICONEXCLAMATION
>     Resume Next

> EditErrorHandler:
>     ErrorCondition = True
>     CONVERTtblVehicleMonthly = False
>     MsgBox "Can't edit Employees table.", MB_ICONEXCLAMATION
>     Resume Next

> End Function



Sun, 10 Oct 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. closing access from code doesn't work, see further down

2. Converting to Access 2002 Code doesn't work

3. old code - new browser - code doesn't work

4. Code doesn't work (from Dev's site)

5. An access 95 program doesn't work on access 2000

6. fRefreshLinks Doesn't work if path doesn't exist

7. DDE'd CloseDatabase of Access doesn't work

8. Code converted from macro doesn't work

9. HELP! Code doesn't work any more

10. Code doesn't work, why?

11. 2 questions: Code doesn't work when I split database and Seek/Index question

12. Code doesn't work when new mail arrives

 

 
Powered by phpBB® Forum Software