By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

OnClick Event Code Modification Assistance Needed

USTRAGNU1
P: 36
Good Day. I am trying to force users to enter a date in a date field via VBA in a function in an On Click event in Access 2013.

I find plenty of examples for Before Update or various Focus examples, but nothing for a function in the On Click.

I have attached a small document which I hope illustrates my request very clearly. If you have questions or require additional information, please don't hesitate to ask.

As always, thanks so much in advance to the responders. I appreciate this site. UTSRAGNU1
Attached Files
File Type: docx On Click Event Modification Request - OPS Database.docx (196.6 KB, 120 views)
Apr 6 '17 #1

✓ answered by jforbes

I very nearly didn't open the Word Document. It's just such a virus risk, plus now I have this Word Document on my Desktop that will need to be deleted in the future, but only after your question is successfully handled. ... NeoPa is right, it's a pain.

NeoPa is also right in that you really want to let Access do things the way it wants to, and using a button to force a validation on another field is really not what Access is about.

What I would suggest is to use a Dialog Form in place of your Message Box to capture the Date from the User. Something like this:


I would only enable the Date field if the Checkbox is checked. And only enable the OK button if the either the CheckBox is unchecked or everything is filled in and validated. You can put a Cancel button on there if you feel you need it.

Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,409
You have to bear in mind that the code is generally running in response to events. Forcing a user to enter particular data into the form is not possible from there within the code (Maybe just very inconvenient and totally *rse-about-faced).

Consider putting code somewhere else that can check if the button's been clicked and also whether or not the date matches the required format. It's hard to advise based on the current layout as it isn't well matched for what you want it to do.

NB. Please try to include your questions on the page in the thread. Pictures are handled and text can also be displayed. Linking to a separate document really doesn't work well in a forum environment. Most will simply ignore the thread if they can't see what it is when they look at it.
Apr 6 '17 #2

jforbes
Expert 100+
P: 1,107
I very nearly didn't open the Word Document. It's just such a virus risk, plus now I have this Word Document on my Desktop that will need to be deleted in the future, but only after your question is successfully handled. ... NeoPa is right, it's a pain.

NeoPa is also right in that you really want to let Access do things the way it wants to, and using a button to force a validation on another field is really not what Access is about.

What I would suggest is to use a Dialog Form in place of your Message Box to capture the Date from the User. Something like this:


I would only enable the Date field if the Checkbox is checked. And only enable the OK button if the either the CheckBox is unchecked or everything is filled in and validated. You can put a Cancel button on there if you feel you need it.
Attached Images
File Type: png Microsoft Access-TestDatabase_Dialog2.png (5.1 KB, 74 views)
Apr 7 '17 #3

USTRAGNU1
P: 36
SO sorry: I will refrain from attaching documents in the future. Why is that feature still available if everyone is so leery of accepting the files?

Anyway, thanks to all for the usual quick replies, und vielen, vielen dank Herr Beethoven, for the dialog box suggestion/breakdown. A colleague of mine actually suggested that very thing while I was waiting on a reply from Bytes.

I will get right to work on it!

Mike M
Apr 7 '17 #4

NeoPa
Expert Mod 15k+
P: 31,409
Mike M:
SO sorry: I will refrain from attaching documents in the future. Why is that feature still available if everyone is so leery of accepting the files?
It's not something to worry about unduly Mike. You're just starting and obviously doing a good job preparing your question. I felt I had to warn you that you were simply not going about it the way we recommend, and the way that will ensure you get more attention to your question.

The options are there because we have to support attachments of all kinds, as there are various reasons why they may be needed. Those reasons shouldn't include the laying out of your problem. That's what the thread is for.

Again. Just understand that you'll get a much better service here if you work the way we recommend.

@JForbes.
In this case the fact that the file type was displayed as DOCX told me that it was a document without code, so I felt safe enough to have a look. Be very wary if you come across any DOCMs as they are DOCuments that are Macro enabled.

@Mike.
I'm very pleased that you received such good advice from JForbes. Yours was a well-written and well laid-out question. Much easier to understand than most. Please come back with more questions when you need to :-)
Apr 7 '17 #5

USTRAGNU1
P: 36
Ok thanks for the tips!

Mike
Apr 7 '17 #6

Post your reply

Sign in to post your reply or Sign up for a free account.