Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Type mismatch (Access 2000)

    The following function gives the error " type mismatch" :


    Public Function Dummy()
    Dim bappath As String
    Dim sappath As String
    Dim appath As String
    Dim db As DAO.Database
    Dim ws As DAO.Workspace
    Set ws = DBEngine.Workspaces(0)
    Dim PWD As String
    PWD = " password"
    bappath = "C:BEUni.mdb"
    sappath = "C:BELewi.mdb"
    appath = bappath Or sappath
    Set dbs = wsp.OpenDatabase(appath, , , "PWD=" & strpassword)
    End Function


    WHat i wanted to do is the following. The function looks up for given databases, amd if it finds one, for example bappath, to open it with the common name appath.
    appath must be either bappath or sappath,depending on the availability.
    If bappath is present, then appath = bappath, if sappath is present, then appath = sappath.
    Can somebody help me ?

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Type mismatch (Access 2000)

    >>appath = bappath Or sappath<<

    I think it is this bit of code that is doing you in. Access evaluates the right side of the equal as boolean, but appath is a string. What are you trying to do here?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Type mismatch (Access 2000)

    As Mark noted, the statement appath = bappath Or sappath won't work. Try this instead:

    ' Check if bappath exists
    If Dir(bappath) = "" Then
    ' If not, check if sappath exists
    If Dir(sappath) = "" Then
    ' Houston, we have a problem!
    MsgBox "Neither " & bappath & " nor " & sappath " was found!"
    Exit Function
    Else
    ' sappath exists, so use that
    appath = sappath
    End If
    Else
    ' bappath exists, so use that
    appath = bappath
    End If
    Set dbs = ...

  4. #4
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Type mismatch (Access 2000)

    Thank you very much for your reply.My task is rather complicated since
    it must delete modules in a remote database. I use a very efficient code for
    deleting the module and it works, it is not working only in my code below.
    Also, how can i rationalize the code, since i must enumerate 15 cases,in the code below i have mentioned only 2.
    Anyway the followig code cannot delete and i do not know why




    Public Function FEW()

    Dim strBu As String
    Dim StrVa As String
    Dim appath As String
    Dim db As DAO.Database
    Dim ws As DAO.Workspace
    Set ws = DBEngine.Workspaces(0)

    strBu = "C:BEUni.mdb"
    StrVa = "C:BELewi.mdb"

    If Dir(strBu) <> "" Then
    appath = strBu
    Set db = ws.OpenDatabase(appath, False, False, "MS Access;PWD=passwordt")
    Call KillObject(appath, 5, "OhMy")

    ElseIf Dir(StrVa) <> "" Then
    appath = StrVa
    Set db = ws.OpenDatabase(appath, False, False, "MS Access;PWD=passwordt")
    Call KillObject(appath, 5, "MdlOne")
    Else
    'no database found so
    Exit Function
    End If
    End Function

    I receive a message that i cannot delete




    Public Sub KillObject(strDbName As String, acObjectType As Long, _
    strObjectName As String)
    'AcObjectType: acTable = 0, acQuery=1, acForm=2, acReport=3, 'acMacro=4, acModule = 5
    ' this is an example how can i call it from the OnClick event of a form:
    'Call KillObject(BEpath, 0, "products")

    Dim adb As Object
    Set adb = CreateObject("Access.Application")
    adb.OpenCurrentDatabase (strDbName)
    adb.DoCmd.DeleteObject acObjectType, strObjectName
    adb.CloseCurrentDatabase
    Set adb = Nothing
    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Type mismatch (Access 2000)

    You open the database using OpenDatabase. Then you open it again in the KillObject function. So the database is open twice; hence you can't delete objects. Remove the lines with Opendatabase, and specify the password in OpenCurrentDatabase - click in OpenCurrentDatabase and press F1 to get online help.

  6. #6
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Type mismatch (Access 2000)

    thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •