Results 1 to 10 of 10

Thread: Access 2010

  1. #1
    Star Lounger
    Join Date
    Oct 2001
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access 2010

    I have made a gazillion attempts to get a button to work with no success. Someone recommended run Debug - Compile. It is stopping at each little SUB asking for corrections. In the Visual Basic editor can I just delete the ones I know don't work so I can start over clean?

    Thanks.

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    I guess you can do that, but why not fix the ones that show errors, by correcting the errors? Or are those not needed at all?

  3. #3
    Star Lounger
    Join Date
    Oct 2001
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know what is wrong. I have tried the same function in various different ways. For example I get the error "Sub or function not defined" for this code in bold below. I have tried it with and without the brackets

    Private Sub PrintCurrent_Click()
    On Error GoTo PrintCurrent_Click_Err

    DoCmd.RunCommand acCmdPrint
    where "[WRKID]=" & Me![WRKID]


    PrintCurrent_Click_Exit:
    Exit Sub

    PrintCurrent_Click_Err:
    MsgBox Error$
    Resume PrintCurrent_Click_Exit

    End Sub

  4. #4
    Star Lounger
    Join Date
    Oct 2001
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or this one:

    The form has fields from 2 tables - WRKID is the Primary key of one and is the common field. HWID is the primary field for the second one

    Private Sub PreviewReport_Click()
    On Error GoTo PreviewReport_Click_Err

    DoCmd.OpenReport "rHardware", acViewPreview, "", "[HWID]=" & Me!HWID, acNormal


    PreviewReport_Click_Exit:
    Exit Sub

    PreviewReport_Click_Err:
    MsgBox Error$
    Resume PreviewReport_Click_Exit

    End Sub

  5. #5
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    What's with the where line here:

    Code:
    DoCmd.RunCommand acCmdPrint
    where "[WRKID]=" & Me![WRKID]
    That's not a valid statement, AFAIK.

    On the second sub, what error does Access complain about?

  6. #6
    Star Lounger
    Join Date
    Oct 2001
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When I run the second one it says syntax error.

    Do you know how to fix the where line? Basically I am saying to use the number (I think it really should be HWID) for the record I am looking at on the form and print the report for that one record.

  7. #7
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Access should point out the line in error.

    You cannot use a WHERE statement with a DoCmd.RunCommand acCmdPrint, you simply can't. Try DoCmd.ApplyFilter, that takes a WHERE condition and then try printing. I have never tried it, so I am not sure it will work.

  8. #8
    Star Lounger
    Join Date
    Oct 2001
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help. I finally got it.

    Private Sub PreviewReport_Click()
    On Error GoTo Print_Click_Err

    Dim strDocName As String
    Dim strWhere As String
    strDocName = "rHardware"
    strWhere = "[HWID]=" & Me!HWID
    DoCmd.OpenReport strDocName, acPreview, , strWhere

    Print_Click_Exit:
    Exit Sub

    Print_Click_Err:
    MsgBox Error$
    Resume Print_Click_Exit

    End Sub

  9. #9
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Great .

  10. #10
    Star Lounger
    Join Date
    Mar 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am just wondering if this method is better than using "Args" to open a report.
    Thanks a lot.

Posting Permissions

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