- Local time
- Today, 21:17
- Joined
- Jul 9, 2003
- Messages
- 16,689
PDF on MS Access Techniques By Susan J. Dorey
I needed to provide the user with a way to setup up a Form so that it displayed the default date as either UK, USA, International or Medium Date. I did this by providing the user with a integer which would select whichever date format they wanted to display. The form interface provides selection of the date format via an Option Group, this is where the the integer originated from. However, for the default value, the user would have to know which number related to which date format. I know there's a technique to allow you to do this where you can list a number against text and the user chooses the text and the function Returns a number. I couldn't remember what this technique was called hence I searched the internet for Microsoft Access VBA techniques and happened upon this PDF http://www.susandoreydesigns.com/software/AccessVBATechniques.pdf from Susan J. Dorey where I immediately saw the "Enumeration" listed as a technique, and hey presto, that's the one I wanted!
Here's my New Code:-
'1 UK
'2 Medium
'3 USA
'4 International
The Enumeration
Opening the Form and setting the Defaults
I needed to provide the user with a way to setup up a Form so that it displayed the default date as either UK, USA, International or Medium Date. I did this by providing the user with a integer which would select whichever date format they wanted to display. The form interface provides selection of the date format via an Option Group, this is where the the integer originated from. However, for the default value, the user would have to know which number related to which date format. I know there's a technique to allow you to do this where you can list a number against text and the user chooses the text and the function Returns a number. I couldn't remember what this technique was called hence I searched the internet for Microsoft Access VBA techniques and happened upon this PDF http://www.susandoreydesigns.com/software/AccessVBATechniques.pdf from Susan J. Dorey where I immediately saw the "Enumeration" listed as a technique, and hey presto, that's the one I wanted!
Here's my New Code:-
'1 UK
'2 Medium
'3 USA
'4 International
The Enumeration
Code:
Enum enDateFormat
UK = 1
Medium = 2
USA = 3
International = 4
End Enum
Opening the Form and setting the Defaults
Code:
Dim strFrmName As String
strFrmName = "NiftyBetweenDates"
DoCmd.OpenForm strFrmName
With Forms(strFrmName)
.prpStartRange = "01/01/1970" 'If you rem out the date the default date will be used.
.prpEndRange = "01/01/2010" 'If you rem out the date the default date will be used.
.prpFirstDayOfWeek = vbMonday 'If you rem out the first day of the week, the default weekday will be used
.prpDateFormat = enDateFormat.International 'If you rem out the date display format the date will be displayed in UK format by default
End With