' This Windows API call will be used in conjuction with the
' constant EM_SetSel to select the text in the due date field
' after assigning the value to the field.
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_SetSel = &HB1
' Stores the last Due Date Entered
Private sLastDueDate As String
Private Sub DueDate_GotFocus()
' Checks for previosly stored value and checks to make
' sure that the user is not editing an existing production order
If Len(sLastDueDate) > 0 And Len(Me.Item.Text) = 0 Then
' Assign the stored value to the control
DueDate.Text = sLastDueDate
' Select the text on screen, so that the user can
' easily type over the assigned value.
Call SelectText(DueDate)
End If
End Sub
Private Sub DueDate_LoseFocus(AllowLoseFocus As Boolean)
' Only store value if this is a new production order being entered
If Len(Me.Item.Text) = 0 Then
' Store the last Due Date entered.
sLastDueDate = DueDate.Text
End If
End Sub
' This procedure accepts a Macola Text Box as a parameter
' and selects the text on screen.
Private Sub SelectText(ByRef ctl As macEditBox)
Dim iStrLen As Long
iStrLen = Len(ctl.Text)
SendMessage ctl.hwnd, EM_SetSel, 0, iStrLen
End Sub