Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-09-21
3
Medium Priority
?
274 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 39

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 39

Expert Comment

by:PatHartman
ID: 41809320
You're welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

610 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