Results 1 to 3 of 3

Thread: vb code from access 2003 not working for 2000

  1. #1
    Join Date
    Mar 2006
    Posts
    1

    vb code from access 2003 not working for 2000

    It's some fairly simple code that should be working, but doesn't. The error it gives is: Compile error: Wrong number of arguments or invalid property assignment.

    Here's a piece of the code. The problem area is highlighted.

    Private Sub command60_Click()
    On Error GoTo Err_cmd60_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim sCriteria
    sCriteria = "[Field12]=" & "cbodocname"
    stDocName = "rptsrch"
    DoCmd.OpenReport stDocName, acViewPreview, , sCriteria, acWindowNormal
    Exit_cmd60_Click:
    Exit Sub
    Err_cmd60_Click:
    MsgBox Err.Description
    Resume Exit_cmd60_Click
    End Sub

    Thanks!

  2. #2
    Join Date
    Aug 2005
    Location
    Oxford, England
    Posts
    8
    Hi

    According to my copy of access the error message is correct - here is the syntax

    Denis




    DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

    The OpenReport method has the following arguments.

    Argument Description

    reportname A string expression that's the valid name of a report in the current database.

    If you execute Visual Basic code containing the OpenReport method in a library database, Microsoft Access looks for the report with this name first in the library database, then in the current database.
    view One of the following intrinsic constants: acViewDesign, acViewNormal, (default), acViewPreview

    filtername A string expression that's the valid name of a query in the current database.

    wherecondition A string expression that's a valid SQL WHERE clause without the word WHERE.

  3. #3
    Join Date
    Apr 2006
    Location
    Manchester, UK
    Posts
    6
    I think there may be a problem with the where condition:
    sCriteria = "[Field12]=" & "cbodocname"

    If cbodocname is a variable holding a value the code would be:
    sCriteria = "[Field12]='" & cbodocname & "'"

    If cbodocname is an actual value the code would be:
    sCriteria = "[Field12]='cbodocname'"

    Assuming that the value is a string it needs to end up with single quotes around it so the result of the where condition would end up as:
    [Field12]='YourValueHere'

    Hope this makes sense.

Posting Permissions

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