Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecing 'Esc' Key pressed

Status
Not open for further replies.

mo2783

Programmer
Nov 16, 2003
68
0
0
GB
I have a command Button on a form, when cliked will bring up a calender, when the calender is displayed a date has to be selected. For some reason if a date is not selcted and you press the 'Esc' key or the 'x' to close the calender the current date is taken as being the selected date and saved in table, i don't want this to happen, when either of those keys are pressed i want the detec and close the calender down. without anything being saved. Any ideas?
 
Doesn't have your calender a default value you may test ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The calender is default, but is there a way to test whether the 'Esc' or 'x' has been pressed and then take appropirate action?
 
Mo

This may help:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If ocxCalendar.Visible = True Then
If KeyCode = vbKeyEscape Then
cboOriginator.SetFocus
ocxCalendar.Visible = False
End If
End If
End Sub
Hope that's of use mate [colorface]


----------------------------
Cogito Ergo Sum [jester2]
----------------------------
 
another way is to put the code below onto the calendar code

Private Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)

Select Case KeyCode
Case vbKeyReturn ' carriage return
SetAndClose
Case vbKeyEscape ' escape
DoCmd.Close
End Select

End Sub


Hope this helps
Hymn
 
just curious what code is on the button

Hope this helps
Hymn
 
This is the code which calls a class module to bring the calendar.

Private Sub cmdCalender_Click()
Dim strMsg As String
Dim strMsg1 As String
Dim strMsg2 As String
Dim blSuccess As Boolean

txtAppDate = ShowMonthCalendar(mc, Date, Date, , , True)


strMsg = "You have selected a date, thats already expired."
strMsg1 = "You have selected a date, greather then today."
strMsg2 = "Are you Sure this is the Correct Date?"

If txtAppDate < Date Then
If MsgBox(strMsg, vbOKCancel, "Date Error") = vbCancel Then
txtAppDate = ""
End If
ElseIf txtAppDate > Date Then
If MsgBox(strMsg1, vbOKCancel, "Date Error") = vbCancel Then
txtAppDate = ""
End If
End If

If MsgBox(strMsg2, vbOKCancel + vbQuestion, "Date Selected") = vbCancel Then
txtAppDate = ""
Else
blSuccess = UpdateActualAppointmentDate("tblPatientAppointment", txtAppDate)
If blSuccess = True Then
Call SetAppointmentPosition
If mblSuccess = True Then
Call InsertMonthYear("tblPatientAppointment")
End If
Else
MsgBox "A Error occurred when saving appointment date"
End If
End If

End Sub
 
Did either of the two threads work?.
I have a db that calls a calendar form on entering a field and if you press escape it leaves the field blank and moves to the next field. It is currently in A2002 but should convert if you would like a copy let me know


Hope this helps
Hymn
 
hymn,

Neither of the 2 threads worked i would be greatful if i can see a copy of it. Thanks.
 
I'm surprised that no has asked what control or other method you're using to display the calendar? Is it the MS Calendar Control, the DT Picker Control, or you own control?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
That is why I asked. From mo2783's original question:
mo2783 said:
... if a date is not selcted and you press the 'Esc' key or the 'x' to close the calender ...
Does the standard calendar control have an 'x' to close the calendar?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Did the sample db help??

Hope this helps
Hymn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top