Hi Brenda
Is this a single form or a continuous form? The approach is similar, but
slightly different for the two.
Basically, you need an unbound textbox to enter the data. Then you use the
BeforeUpdate event of that textbox to validate the data entered, split the
input into month and year, and create a date which you assign to the real
date field.
Private Sub txtEditExpDate_BeforeUpdate(Cancel As Integer)
Dim iSlash as integer, iMonth as integer, iYear as integer
On Error Goto ProcErr
With Me!txtEditExpDate
iSlash = Instr(.Value, "/")
If iSlash = 0 then
Cancel = True
Goto ProcEnd
End If
iMonth = CInt( Left( .Value, iSlash-1 )
iYear = CInt(Mid( .Value, iSlash + 1 )
End If
' we now have a month and a year
If iMonth<1 or iMonth>12 then
Cancel = true
Goto ProcEnd
End If
' for first of month:
Me!ExpDateField = DateSerial( iYear, iMonth, 1 )
' or for last of month:
Me!ExpDateField = DateSerial( iYear, iMonth + 1, 0 )
ProcEnd:
If Cancel then MsgBox "Invalid expiry month - enter as mm/yy"
Exit Sub
ProcErr:
Cancel = True
Resume ProcEnd
End Sub
Your Form_Current event procedure needs to set the value of the unbound
textbox:
txtEditExpDate = Format( ExpDateField, "mm/yy" )
Now, for a single form, the real date field doesn't even need its own
textbox - the job is done.
For a continuous form, add a bound textbox for the expiry date, with a
format "mm/yy". Make this bound textbox enabled and locked.
Place your unbound editing textbox exactly over the top of it, then do
Format>Send to back. This will ensure it is always behind the real field
unless it has the focus.
Finally, add a GotFocus event procedure for the real (bound) textbox:
txtEditExpDate.SetFocus