Programmatically change a controls format property

I have a search form that has 2 unbound controls a combo box (cboSearchField) and a text box (txtSearchString) the combo box is used to select the search criteria and the Text box is the search string, one of the criteria is a date (CountDate). What I want to do is programmatically change the controls format property to “Short Date” when the combo box contains CountDate, so that the calendar displays, and reset it back for non-date searches. BTW this is Access 2007.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What other search criteria do you have - numbers, boolean, strings?
In the AfterUpdate event procedure for the cboSearchField control, put

if cboSearchField = "CountDate" then
    txtSearchString.format = "Short Date"
    txtSearchString.format = ""
end if

Open in new window

You may also need to put this code in your form OnCurrent event procedure. You can create a subroutine that contains the above code, and execute it from both the control AfterUpdate and form OnCurrent event procedures.

I don't think the calendar will appear unless the date field is a bound control.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skull52Author Commented:
Text, Yes/No
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

skull52Author Commented:
The calender does appear, with unbound controls, I will test your code.
skull52Author Commented:
I tried putting the code where you suggested in the AfterUpdate and OnCurrent events but it didn't work, so I added it to the GotFocus event of txtSearchString and added .Value to cboSearchField  of your code and that seemed to work. Thanks for the help.
Private Sub txtSearchString_GotFocus()
If cboSearchField.Value = "CountDate" Then
    txtSearchString.Format = "Short Date"
    txtSearchString.Format = ""
End If
End Sub

Open in new window

skull52Author Commented:
See my last post for further instructions
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.