Results 1 to 3 of 3

Thread: Type Mismatch

  1. #1
    Join Date
    Apr 2004

    Unanswered: Type Mismatch

    I'm trying to select the first record within a Query that I have built in Access so that I can filter out all the records from a given date. Then I want to take these records and save them in an array. I have the following code:

    Sub DisplayForm()
    Dim strConPath As String

    DateCheck = GetDate.DateBox.Text
    strConPath = "Z:\CSGG2_be.mdb"

    ' Create new instance of Microsoft Access.
    Set appAccess = CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strConPath, True
    ' Open Orders form.
    appAccess.DoCmd.SelectObject acQuery, , True
    appAccess.DoCmd.OpenQuery "CustomerService", acReadOnly
    appAccess.DoCmd.GoToRecord , acDataQuery, "CustomerService", acFirst
    End Sub

    When it gets down to the GoToRecord it says Type mismatch. Any clue as to where this is? or what is causing it?

    Thanks in advance!

  2. #2
    Join Date
    Mar 2004
    Victoria, Canada
    I've had a heck of a time with the libraries in my code because I have been using access for years. The order of the libs VBA ... 5.3 and DAO 3.6 being wrong causes mysterious errors like that...

  3. #3
    Join Date
    Apr 2004
    outside the rim
    Dim appAccess As Access.Application

    You don't want Microsoft guessing what referece to use. Explicit Referencing is also the reliable fix to Fisherman's problem with the order of the libraries - when you explicitly reference, you tell it which library to use, so you don't end up at the mercy of the "reference priority".

    As for the rest of the code, try this:
    Set appAccess = CreateObject("Access.Application")
    appAccess.OpenCurrentDatabase strConPath, True
    appAccess.DoCmd.OpenQuery "q1", acViewNormal, acReadOnly
    appAccess.DoCmd.GoToRecord acDataQuery, "q1", acFirst

    Where "q1" is your query.
    Notice several changes:
    1) I removed the "SelectObject" command as it is not necessary
    2) I added "acViewNormal" to "OpenQuery"command - here was your main problem: the default open mode in Edit, and trying to change records in Edit mode is what generated the error.
    3) I removed the extra "," in the GotoRecord command.

    This assumes Access 97; I ran the code in Excel after making sure Access.Application was referenced. It SHOULD work in any VB environment and with other Access versions, although some minor tweaking may be required.

    Have fun!

Posting Permissions

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