Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2012
    Posts
    126

    Unanswered: Need help with this docmd.printout command. Need If statement for no record

    I need to an an If statment with msgbox to handle no record selected. I have a subform that lists our current projects and a print button that prints the project based on record selected. The problem I have is if there is no record selected it prints all records.

    Private Sub cmdPrint_Click()
    On Error GoTo Err_cmdPrint_Click

    DoCmd.OpenReport "rptWorkOrder", , , "ProjectID = " & Me!ProjectID
    DoCmd.PrintOut


    Exit_cmdPrint_Click:
    Exit Sub
    Err_cmdPrint_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrint_Click
    End Sub

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    well you could test for the number of records prior to execting the do cmd using say a domain function such as dcount
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2012
    Posts
    126
    Quote Originally Posted by healdem View Post
    well you could test for the number of records prior to execting the do cmd using say a domain function such as dcount

    I was thinking or hoping for something along the lines of my list box report print button
    Private Sub cmdPrintReport_Click()
    If Nz(Me.ListBoxForReports, "") <> "" Then
    DoCmd.OpenReport ListBoxForReports, acNormal
    Else
    MsgBox ("You Must First Select a Report To Print!")
    Me.ListBoxForReports.SetFocus
    End If

    Me.ListBoxForReports = Null
    End Sub
    Big thank you for the fast reply btw

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Thats what i was thinking of but use dcount in place of your nz clause
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Aug 2012
    Posts
    126
    would it be like this then?

    Private Sub cmdPrintReport_Click()
    If dlookup([frmdashboard]!frmOpenProjects.projectID, "") <> "" Then
    DoCmd.OpenReport rptWorkOrder, acNormal
    Else
    MsgBox ("You Must First Select a Report To Print!")
    frmdashboard]!frmOpenProjects.SetFocus
    End If

    frmdashboard]!frmOpenProjects.projectID= Null
    End Sub
    Never used the dlookup in access before honestly.

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    He said DCount, not DLookup, but you can check for selections in a Listbox using this:

    If Me.ListBoxForReports.ItemsSelected.Count > 0 Then

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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