?
Solved

Display contents of a field in a message box - MS Access

Posted on 2016-09-21
3
Medium Priority
?
200 Views
Last Modified: 2016-09-21
I have an Access form for adding records.  One of the fields on the form requires a date to be entered.  When the user presses the command button on the form to add a record, the date entered in the textbox is checked against a table I have that lists invalid dates.

That table has two fields.  Field1 contains the invalid date value. Field2 contains a description of why it is invalid.

So, for example, a record in the table may look like this:

Field1              Field2
9/19/2016      Closed for renovations

To check if an invalid date is selected, I currently have the following code:

If CBool(DCount("*", "MyDatesTable", "[Invalid_Date] = #" & Format(Forms![MyForm]![MyDateTextbox].Value, "yyyy\/mm\/dd") & "#")) Then
     MsgBox "Invalid Date Selected"
End If

What I'd like to be able to is, in addition to the message box indicating an invalid date was selected, I would also like to display why it's invalid. Therefore, if a matching date is found in the table with what was entered in the textbox, I'd like to be able to display the contents of Field2 for that record.

So, if 9/19/2016 was selected (and presuming it's in the table as an invalid date due to business having been closed for renovations), I'd like to be able to display Field2's contents (i.e. "Closed for renovations") in the messagebox.  I don't care where in the messagebox it is displayed just as long as it is displayed.  Thank you.
0
Comment
Question by:dbfromnewjersey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 41809055
Then use DLookup() rather than DCount()
Dim ErrDesc as Variant
ErrDesc = DLookup("Field2", "MyDatesTable", "[Invalid_Date] = #" & Format(Forms![MyForm]![MyDateTextbox].Value, "yyyy\/mm\/dd") & "#")
If Not IsNull(ErrDesc) then
    Msgbox  "Invalid Date Selected - " & ErrDesc, vbOKOnly
End If

Open in new window

0
 

Author Comment

by:dbfromnewjersey
ID: 41809138
Thank you.
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 41809320
You're welcome
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question