Results 1 to 4 of 4
  1. #1
    Xine is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    19

    Smile button activating the query-report is only to run if (unbound) field is not blank --- vba issues

    So the button's code below works, but only once. After that, the report generates with or without content in the "UserTitle" field. I really need UserTitle content to be required and notify the user when it isn't.

    Private Sub Run_Srch_Click()

    Dim stDocName As String
    stDocName = "qry_FilterUserReport"

    If IsNull([UserTitle]) Then
    MsgBox "You must give the report a title."
    Cancel = True


    Me.UserTitle.SetFocus
    Else
    DoCmd.OpenReport "rpt UserGeneratedDonRpt", acViewReport
    End If

    End Sub

  2. #2
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    Someone else might be able to confirm this but I'm wondering whether if once you've passed focus to the userTitle and then moved on access is considering that it is no longer null and just has a blank value which isn't the same as null. I.e maybe include an elseif in between your line Me.UserTitle.SetFocus and Else to say Elseif [UserTitle] ="" Then
    MsgBox"You must...etc" Cancel = True then SetFocus to UserTitle again

  3. #3
    Xine is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    19
    Okay, The issue WAS with the clear button. I switched to:
    me.UserTitle.value = null
    instead of = "" and now it's working.
    THANK YOU SO MUCH!

  4. #4
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    All good - glad I could help. As per my post you could have included it in the Run_Srch button but I didn't know you had a Clear button.

    Just remember null and blank ("") are different things. Null has no value and blank has a value of nothing.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 20
    Last Post: 01-18-2016, 12:10 AM
  2. Replies: 2
    Last Post: 11-08-2015, 02:10 PM
  3. Replies: 5
    Last Post: 01-30-2015, 02:45 PM
  4. Replies: 5
    Last Post: 06-22-2011, 08:47 PM
  5. Replies: 5
    Last Post: 09-16-2009, 05:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums