PDA

View Full Version : A date picker userform for Mac.



mikerickson
08-20-2011, 12:01 AM
People have been inquiring about a Date Picker for Mac, so I came up with this userform.
The syntax for using it is
Dim uiDate As Double
Dim strPrompt As String
strPrompt = "Please enter the date of your choosing."

uiDate = macDate.Chosen(strPrompt, Default:=DateSerial(1919, 5, 3), Title:="Pick a Date", DefaultButton:=vbDefaultButton1)
' all arguments are optional
' defaults prompt="Choose a date.", default=today's date, title="Choose Date", defaultButton=vbDefaultButton1

If uiDate = False Then
Rem MsgBox "canceled"
Else
MsgBox "You chose " & Format(uiDate, "d. mmm, yyyy.")
End If


The sub FillMacDateWithControls will take an empty userform, named macDate, and put the necessary controls in the proper place.

KevCarter
12-24-2013, 10:17 AM
Very cool example. I'm surprised not any discussion after you uploaded. I found this with a google search for Mac Date Picker after I wrote my own for use within a form. Yours is a TON more comprehensive, and there is so much to learn in your demo. Thanks very much for sharing it!

Kevin

milouchien
12-27-2013, 11:46 AM
Yes this is the most elegant out there... Forgive my ignorance, but could you tell me if this would work from another user form? And insert eh chosen date into a text box?Even if you can't answer, thank you.David

mikerickson
12-27-2013, 12:17 PM
It should work from another userform.

I'm at work and can't test, but I would create a userform, with a command button, a text box and this code and see what happens.

Private Sub CommandButton1_Click()
Dim uiDate As String

uiDate = macDate.Chosen

If uiDate = False Then
MsgBox "canceled"
Else
TextBox1.Text = Format(uiDate, "mm/dd/yyyy")
End Sub
The userform that is the date picker must be named macDate.

milouchien
12-27-2013, 05:30 PM
Wow that was a quick reply! I was going to say don't worry because Ive solved it - using your form of course...Seems to work perfectly using an adapted version of your implementation codeTruly grateful for your generosity...David

florianreply
02-03-2015, 12:45 AM
It should work from another userform.

I'm at work and can't test, but I would create a userform, with a command button, a text box and this code and see what happens.

Private Sub CommandButton1_Click()
Dim uiDate As String

uiDate = macDate.Chosen

If uiDate = False Then
MsgBox "canceled"
Else
TextBox1.Text = Format(uiDate, "mm/dd/yyyy")
End Sub
The userform that is the date picker must be named macDate.

__________


mikerickson you are the bomb! totally saved my life it would have taken me months if not years to determine how to program that. thank you for sharing your knowledge and please continue to do so!

dmc311
04-09-2015, 10:30 AM
Very cool. thanks Mike.

dmc311
04-11-2015, 09:37 AM
Sorry to resurrect an old discussion, but I can't figure out why the user form provided my Mike resizes based on the location of the Cancel button. I downloaded the sample file, and am just looking to move the Cancel and OK buttons below the calendar vs. to the right of the calendar. When I do this, the with of the entire form automatically resizes to where ever the cancel button is located. Example: If i move the cancel button to below the calendar to the left, the width of the entire form shrinks (see attached image). Conversely, if I move the Cancel button way out to the right the form expands. Note: the OK button seems to have no impact on the form size.

I can't seem to figure out what's causing this. Any help would be appreciated.

13144

sophia.ho
04-15-2015, 06:24 AM
Thank you!


It should work from another userform.

I'm at work and can't test, but I would create a userform, with a command button, a text box and this code and see what happens.

Private Sub CommandButton1_Click()
Dim uiDate As String

uiDate = macDate.Chosen

If uiDate = False Then
MsgBox "canceled"
Else
TextBox1.Text = Format(uiDate, "mm/dd/yyyy")
End Sub
The userform that is the date picker must be named macDate.

ty27386
07-07-2015, 10:10 AM
People have been inquiring about a Date Picker for Mac, so I came up with this userform.
The syntax for using it is
Dim uiDate As Double
Dim strPrompt As String
strPrompt = "Please enter the date of your choosing."

uiDate = macDate.Chosen(strPrompt, Default:=DateSerial(1919, 5, 3), Title:="Pick a Date", DefaultButton:=vbDefaultButton1)
' all arguments are optional
' defaults prompt="Choose a date.", default=today's date, title="Choose Date", defaultButton=vbDefaultButton1

If uiDate = False Then
Rem MsgBox "canceled"
Else
MsgBox "You chose " & Format(uiDate, "d. mmm, yyyy.")
End If


The sub FillMacDateWithControls will take an empty userform, named macDate, and put the necessary controls in the proper place.

mikerickson
07-11-2015, 12:50 PM
... looking to move the Cancel and OK buttons below the calendar vs. to the right of the calendar. ....


Change this section in the Useform_Activate code.

With Me
.Height = Application.Max(.butCancel.Top + .butCancel.Height + 10, frameUserEntryControls.Top + .frameUserEntryControls.Height + 35) + (.Height - .InsideHeight)
.Width = Application.Max(2 * .frameUserEntryControls.Left + .frameUserEntryControls.Width, .butCancel.Left + .butCancel.Width + 10) + (.Width - .InsideWidth)
.Tag = "shown"
End With

Ron de Bruin
09-06-2015, 12:57 PM
Got one also on my site, can't post a link because of this error.

>Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words.

Can anybody tell me how to post a link

mikerickson
09-07-2015, 01:17 PM
Here's the link to Ron's date picker
http://www.rondebruin.nl/mac/addins/datepicker.htm

mancubus
09-09-2015, 06:46 AM
your post count should be at least 5 in order to post a link Ron.

you are an old member. hope to see you here more often.

btw, thanks for your excellent site.