• Type mismatch (Access 2000)

    Author
    Topic
    #398814

    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 ?

    Viewing 3 reply threads
    Author
    Replies
    • #765461

      >>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?

    • #765462

      >>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?

    • #765469

      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 = …

      • #765603

        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

        • #765609

          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.

        • #765610

          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.

      • #765604

        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

    • #765470

      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 = …

    Viewing 3 reply threads
    Reply To: Type mismatch (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: