Results 1 to 3 of 3
  1. #1
    rshaw63 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    32

    Can I Have a message Box Pop up on Form Load from a button

    Hello all,



    I am trying to create a pop up window with information from a query when i click a button on my main screen. How do i tell it to use the contents of the query as information passed to the msg box?

    A little history about this task i had created a query based on information from a table i have. For the Criteria i used IIf([Dig_Permit_Terminated]<=Date()-5,Null). Hard to test unless i have records to show in that query I know. what i would like for information in the Msg Box are as follows: Field Name : Dig_Permit_Number & Project_Number & UNCC_Number & Dig_Permit_Terminated. if there not any that match the criteria then a simple "Nothing is due at this time."

    Is it as simple as that or i have to connect to that table correct to pull that information from so far i have gotten to here:

    Code:
    Private Sub Form_Load()DoCmd.OpenQuery "MsgBox_Dig_Permits"
    Dim ID As Long
    ID = Nz(DLookup("[Dig_Permit_Terminated]", "Dig_Permits", "Dig_Permit_Terminated=<#" & Date - 5 & "#"), 0)
    If ID <> 0 Then
    DoCmd.OpenForm "msgbox_frm"
    Else
    MsgBox " Currently No Dig Permits need Renewed", vbOKOnly

  2. #2
    rshaw63 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    32
    So i think i am on the right track however still not working like i want. It is not popping up message box and it is giving me an error on the second line of code above. I am not sure if it is due to no matches in the database or what.

    any help is as always appreciated.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    It's failing on the DLookup()? Odd that you're looking up the date, not sure if that would throw an error putting a date into a Long. In the Immediate window type:

    ?DLookup("[Dig_Permit_Terminated]", "Dig_Permits", "Dig_Permit_Terminated=<#" & Date - 5 & "#")

    hit enter and see what result you get. I'd expect you to be counting records or returning an ID, though if there were more than one you'd only get the first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 03-22-2019, 05:35 PM
  2. Replies: 3
    Last Post: 10-23-2017, 02:09 PM
  3. Replies: 2
    Last Post: 09-05-2016, 07:23 AM
  4. Replies: 15
    Last Post: 03-16-2015, 06:30 AM
  5. Replies: 3
    Last Post: 07-13-2011, 02:04 PM

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