Link to home
Start Free TrialLog in
Avatar of Fred Webb
Fred WebbFlag for United States of America

asked on

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.
Avatar of GRayL
GRayL
Flag of Canada image

What other search criteria do you have - numbers, boolean, strings?
ASKER CERTIFIED SOLUTION
Avatar of pdebaets
pdebaets
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fred Webb

ASKER

Text, Yes/No
pdebaets,
The calender does appear, with unbound controls, I will test your code.
pdebaets
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"
Else
    txtSearchString.Format = ""
End If
End Sub

Open in new window

See my last post for further instructions