Date field

  • Thread starter Thread starter Ayesha via AccessMonster.com
  • Start date Start date
A

Ayesha via AccessMonster.com

I have a text box in which i would be entering the date of birth of a person
in the following format
16/5/1977 or 16-5-1977. I want the text box to allow only numbers 0-9, / , -
, backspace, delete, tab. How do i do this.


Regards
Ayesha.
 
Create an event procedure "On Key Down" for the field and test each key that
is entered. The following tests for the minus and plus keys and increments
the date via a further function...

Private Sub txtInvDate_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyAdd Or KeyCode = vbKeySubtract Then
Me!txtInvDate = pproc_PlusMinusKey(KeyCode, Shift, Nz(txtInvDate, 0))
KeyCode = 0
End If
End Sub
 
I want this to happen in Key press event of the textbox .
It gives an compile error for the following statement

pproc_PlusMinusKey(KeyCode, Shift, Nz(txtInvDate, 0))
Regards
Ayesha
 
Open the form in Design View, click on the textbox and open it Properties.
On the Data tab you will see an option for an Input Mask. Click in the box
then click the ... button that appears to the right of the box. If the field
is defined in the table as Date/Time, you will get options for limiting the
entry to dates and/or times. If you don't like with ones offered, you can
create your own.
 
Assuming you declared pproc_PlusMinusKey to be a sub, you either need to use
the Call keyword, or leave out the parentheses:

Call pproc_PlusMinusKey(KeyCode, Shift, Nz(txtInvDate, 0))

or

pproc_PlusMinusKey KeyCode, Shift, Nz(txtInvDate, 0)

I prefer the former syntax, as it makes the fact that it's a subroutine call
more obvious.
 
Back
Top