Property ShowDatePicker

beef

Registered User.
Local time
Tomorrow, 04:49
Joined
Jan 11, 2003
Messages
64
I have just installed 2010, mainly because we have gone that way at work.

I would like to know if there is a way, via VBA, I can turn off the Property ShowDatePicker on all my forms without having to open every form that has a date control and them manually change the property setting to Never.

Many thanks

PS I am new to 2010
 
Lou,
I'm just starting with 2010 also.
I wrote a routine a couple of weeks ago in response to a poster.

The code and post are at
http://www.accessforums.net/access/list-all-control-names-all-forms-access-31409.html

You could look for the specific control and perhaps change the property.
I haven't tried that. The code may be helpful.

With the code, the Treeview, Browser and Calendar show up as Custom Controls
Code:
form_name       control_name	control_type
MyForm	          MyBrowser	Custom control  119
Form11	          TreeView0	Custom control  119
frmCalendar	   Calendar0	Custom control  119
but the control name, at least in my case, helps discriminate the types of controls.

Good luck.
 
Last edited:
Many thanks for that advice.

I will give it a try.
 
I created a dummy form in 2010 to test. I find that all textboxes, controlType 109 have a ShowDatePicker property.

My testing shows
ShowDatePicker 0 means Never
ShowDatePicker 1 means ForDates

I wrote a small proc to check the controls on the form. My form (frmAncestors) has

Name
BirthDate
DeathDate
ID

with default labels for each.

In design mode I set the Birth and Death dates to ShowDatePicker ForDates

I ran my proc to see the numeric values. I then ran the proc and changed the

prp.Values where they were not = 0, using
Code:
90              If prp.Value <> 0 Then
100                    prp.Value = Never
110            End If

When I check the ShowDialogPicker of the textboxes, they all show Never.

Here is the code:
Code:
'---------------------------------------------------------------------------------------
' Procedure : CheckForDatePicker
' Author    : Jack
' Date      : 02/02/2013
' Purpose   : To determine the property and values that equate to
'       ShowDatePicker   Never | ForDates
'
' Using form  frmAncestor with Name, BirthDate, DeathDate and ID fields (bound to table)
'
' I determined that all textboxes have a ShowDatePicker Property
'  Never  = 0 | ForDates = 1
'
'---------------------------------------------------------------------------------------
'
Sub CheckForDatePicker()
    
    
    Dim ctl As Control
    Dim prp As Property
    Dim objActiveForm As Form

  Const Never = 0, ForDates = 1
   On Error GoTo CheckForDatePicker_Error

10        On Error Resume Next
20        DoCmd.OpenForm "frmAncestor", acDesign
30    Set objActiveForm = Application.Screen.ActiveForm

40    For Each ctl In objActiveForm.Controls
50      If ctl.ControlType = 109 Then      'TextBox is controltype  109
60          For Each prp In ctl.Properties
70              If prp.name = "ShowDatePicker" Then
80                  Debug.Print Now & "  " & ctl.name & "  " & ctl.ControlType & "  " & prp.name & "  " & prp.Value
'
'   ***    Uncomment this If to Set all textbox ShowDatePicker  to "Never"   ***
90              ' If prp.Value <> 0 Then
100             '       prp.Value = Never
110             '  End If

120             End If
130         Next prp
140     End If
150   Next ctl

   On Error GoTo 0
   Exit Sub

CheckForDatePicker_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure CheckForDatePicker of Module AWF_Related"
End Sub
 
Last edited:
Hi Jack

I thank you for your code as it fuctions as expected.

I have one further request and that is.

How would I go about creating a module (function) then calling that function on a forms load properties.

That way it can be used on all forms that has a textbox control for dates


Hope this makes sense
 
Hi Jack

I have continued to modify your original code and I have tested it and it works as I wanted to work.

1 - I created a module titled modCheckForDatePicker then modified the code.

Code:
Function CheckForDatePicker(pF As Form)
    On Error Resume Next
    Dim ctl As Control
    Dim prp As Property
    Const Never = 0, ForDates = 1

    For Each ctl In pF.Controls
        If ctl.ControlType = 109 Then      'TextBox is controltype  109
            For Each prp In ctl.Properties
                If prp.name = "ShowDatePicker" Then
                    If prp.Value <> 0 Then
                        prp.Value = Never
                    End If
                End If
            Next prp
        End If
    Next ctl
End Function

2 - I then in my forms OnLoad code I have this CheckForDatePicker Me

3 - Then when the form loads it changes the ShowDatePicker to Never

Hope this helps

Please feel free to claim this as yours, as it was you that provided the intitial code.
 
After a little trial an error, I would recommend a single run to change the ShowDatePicker property value of all the textboxes on all forms. I wouldn't mess with the Load events etc.

However, here is a method with Load Event.

I used the Form Load event, but when I intercepted and asked to Open the form in design view, Access complained -- I couldn't do that operation at this time. So I figured the user wants to Open the Form, so if he starts the Open, and I close the Form, then immediately open if in design mode, make my changes to ShowDatePicker property for every text box. then close the form, then Reopen the Form Normal.

I was able to use the form's Load event, but I had to
a) use a global variable to prevent redoing(looping the changes) and
b) had to include the global variable in the Load EventS

Private Sub Form_Load()
If Glbl = True Then
Call SetShowDatePickerToNever(Me.name)
End If
End Sub

I mocked up a proc to open 2 forms, altered the Load Events

Code:
Sub testSetShowDatePickerToNever()

DoCmd.SetWarnings False
Glbl = True
DoCmd.OpenForm "frmAncestor"
Glbl = True
DoCmd.OpenForm "Customers"
End Sub
and ran this code

Code:
'---------------------------------------------------------------------------------------
' Procedure : SetShowDatePickerToNever
' Author    : Jack
' Date      : 02/02/2013
' Purpose   : Function to use a Form's name and the Load event to
' iterate all text boxes and change the ShowDatePicker property.
'
'
'  Needs a Global Parameter
'       Global Glbl As Boolean
'
'---------------------------------------------------------------------------------------
'
Sub SetShowDatePickerToNever(frmName As String)
          
          Dim ctl As Control
          Dim prp As Property
          Dim objActiveForm As Form

         Const Never = 0, ForDates = 1
10       On Error GoTo SetShowDatePickerToNever_Error

20        DoCmd.Close acForm, frmName   ' close the user's open event
30        Glbl = False  'set to False to bypass Loop in  Form.Open  event
40        Debug.Print " Glbl  " & Glbl
50        DoCmd.OpenForm frmName, acDesign  'open for design and change
60    Set objActiveForm = Application.Screen.ActiveForm

70    For Each ctl In objActiveForm.Controls
80      If ctl.ControlType = 109 Then      'TextBox is controltype  109
90          For Each prp In ctl.Properties
100             If prp.name = "ShowDatePicker" Then
110                 Debug.Print Now & "  " & ctl.name & "  " & ctl.ControlType & "  " & prp.name & "  " & prp.Value
      '
      '   ***    Uncomment this If to Set all textbox ShowDatePicker  to "Never"   ***
120              If prp.Value <> 0 Then
130                    prp.Value = Never
                       Debug.Print Now & "  " & ctl.name & "  " & ctl.ControlType & "  " & prp.name & "  " & prp.Value
140              End If
 
150             End If
160         Next prp
170     End If
180   Next ctl
190   DoCmd.Close acForm, frmName  'close my  reset the ShowDatePicker activity
200   DoCmd.OpenForm frmName, acNormal  'make it look like the users Open Form (now showdatpicker is set to never)
210      On Error GoTo 0
220      Exit Sub

230      On Error GoTo 0
240      Exit Sub

SetShowDatePickerToNever_Error:

250       MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure SetShowDatePickerToNever of Module AWF_Related"

End Sub

Here is the debug.print output
Code:
 Glbl  False
02/02/2013 9:10:18 PM  name  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  name  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  birthdate  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  birthdate  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  deathdate  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  deathdate  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  id  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  id  109  ShowDatePicker  0
 Glbl  False
02/02/2013 9:10:18 PM  CustomerID  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  CustomerID  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  CompanyName  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  CompanyName  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  ContactName  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  ContactName  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  ContactTitle  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  ContactTitle  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  Address  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  Address  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  City  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  City  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  Region  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  Region  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  PostalCode  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  PostalCode  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  Phone  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  Phone  109  ShowDatePicker  0
02/02/2013 9:10:18 PM  Fax  109  ShowDatePicker  1
02/02/2013 9:10:18 PM  Fax  109  ShowDatePicker  0


Good luck.


OOOPS:

Just saw you had posted. I like your concise code.
I started with a Form as parm but got an error and reverted back to frmName.

Glad you have it working.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom