Results 1 to 7 of 7
  1. #1
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    2,144
    Thanks
    177
    Thanked 205 Times in 197 Posts

    runtime error 13

    Just tried running a VBA script (Access 2016) which has worked fine for quite a time. However it's now giving me the following error:

    runtime error 13
    Type mismatch

    It stops on the second of these statements, but I think it may be the first causing the problem

    Code:
    Set MyDB = CurrentDb
    Set rsOutput = MyDB.OpenRecordset("tblTempPhotographs", dbOpenTable)
    My dim statements are:

    Code:
        Dim MyDB            As Database
        Dim rsOutput        As Recordset
    I've Googled but can't see anything that helps.
    If I save the whales where do I keep them?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,141
    Thanks
    432
    Thanked 1,643 Times in 1,480 Posts
    Access,

    Your basic code is correct as this working example from one of my DBs shows.
    Code:
    Private Sub Form_Load()
    
       Dim zSQL             As String
       Dim dbsSCL           As Database
       Dim rst              As Recordset
       
       Set dbsSCL = CurrentDb
       zSQL = "SELECT DISTINCT SyntaxType From SourceCode"
       Set rst = dbsSCL.OpenRecordset(zSQL)
       
       With lboxSyntaxTypes
           .RowSource = vbNullString
           .AllowValueListEdits = False
           .AddItem "ALL"
           Do While Not rst.EOF
             .AddItem rst.Fields("SyntaxType")
             rst.MoveNext
           Loop
           .Selected(0) = True
       End With
       
       With Me
           .FilterOn = False
           .lboxTitle.Selected(0) = True
       
    '   Me.cmdExit.BackColor = vbRed
       End With    'Me
       
    '*** Switches to determine if Add or Delete code is in progress ***
       bDeleteCodeSwitch = False
       bAddCodeSwitch = False
       
    End Sub            'Form_Load()
    One thing is the CurrentDB a .mdb or a .accdb file? My example works with a .mdb file.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    2,144
    Thanks
    177
    Thanked 205 Times in 197 Posts
    Ahh, yes, I converted the database to an .accdb file not long ago so that must be it. What should the code be?
    If I save the whales where do I keep them?

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,141
    Thanks
    432
    Thanked 1,643 Times in 1,480 Posts
    Sorry, can't help with that as I've stuck with .mdb files.

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,620
    Thanks
    0
    Thanked 35 Times in 34 Posts
    replace
    Code:
       Dim MyDB            As Database
       Dim rsOutput        As Recordset
    with
    Code:
        Dim MyDB            As DAO.Database
        Dim rsOutput        As DAO.Recordset

  6. The Following 2 Users Say Thank You to patt For This Useful Post:

    access-mdb (2017-12-21),RetiredGeek (2017-12-21)

  7. #6
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    2,144
    Thanks
    177
    Thanked 205 Times in 197 Posts
    Thanks patt, that worked. But I remembered after I had shut down last night I have another script that worked with similar commands. But what I hadn't done in that script was have a Dim statement for the variables. So I commented them out on this script and it worked as well. So it either needs the DAO or it doesn't need to have a Dim statement. I will add the Dim statement with DAO as that's always safer anyway.
    If I save the whales where do I keep them?

  8. #7
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    746
    Thanks
    76
    Thanked 94 Times in 89 Posts
    Some people like Dim DAO but I prefer Dim Sum!


Posting Permissions

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