vbOK to setfocus

  • Thread starter Thread starter Haggr1 via AccessMonster.com
  • Start date Start date
H

Haggr1 via AccessMonster.com

why is "Job_Number.setfocus" generating an error that I need to save the
record?


Private Sub Job_Number_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Job_Number) = True Then
'an error message
ElseIf DCount("*", "Table1", "[Job Number]=" & Me.Job_Number & _
" AND [Date To]>Date()-10") = 0 Then
If MsgBox("NOT A VALID JOB NUMBER" & vbNewLine _
& " SEE RICK OR DENNIS", vbOKCancel) = vbOK Then
Job_Number.SetFocus

Else
MsgBox "What Cancel I Just Told You" & vbNewLine _
& " NOT A VALID JOB NUMBER"

End If

End If


End Sub
 
You need to cancel the Before Upate. You will not have to set focus because
it will remain on the control.

Private Sub Job_Number_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Job_Number) = True Then
MsgBox "No Job Number Entered"
Cancel = True
Else
If IsNull(DLookup("[Job Number]", "Table1", "[Job Number]= " &
Me.Job_Number & _
" AND [Date To] > #" & DateAdd("d", -10, Date() &
"#"")) Then
MsgBox("NOT A VALID JOB NUMBER" & vbNewLine _
& " SEE RICK OR DENNIS", vbOK)
Cancel = True
End If

End Sub
 
That works, 2 things: can the incorrect data be highlighted so correct data
can be entered without having to backspace or delete.

And I need a way for the user to get out of that loop even though the data is
incorrect "Skip"?
 
That works, 2 things: can the incorrect data be highlighted so correct data
can be entered without having to backspace or delete.

You can use Me.Job_Number.Undo to erase the user's erroneous input; or you can
set Me.Job_Number.SelStart to 1 and SelLen to Len(Me.Job_Number) to highlight
the content of the control.
And I need a way for the user to get out of that loop even though the data is
incorrect "Skip"?

Now that I don't understand. Do you want to check for incorrect data, and
allow incorrect data to be entered anyway???

John W. Vinson [MVP]
 
I may not use it, but I would like to know how in case for whatever reason I
have to. thanks
 
The IfNull part of this procedure doesn't work
You need to cancel the Before Upate. You will not have to set focus because
it will remain on the control.

Private Sub Job_Number_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Job_Number) = True Then
MsgBox "No Job Number Entered"
Cancel = True
Else
If IsNull(DLookup("[Job Number]", "Table1", "[Job Number]= " &
Me.Job_Number & _
" AND [Date To] > #" & DateAdd("d", -10, Date() &
"#"")) Then
MsgBox("NOT A VALID JOB NUMBER" & vbNewLine _
& " SEE RICK OR DENNIS", vbOK)
Cancel = True
End If

End Sub
why is "Job_Number.setfocus" generating an error that I need to save the
record?
[quoted text clipped - 17 lines]
 
The .undo does highlight the incorrect data. I would like to erase it. Is
it possible?
 
The .undo does highlight the incorrect data. I would like to erase it. Is
it possible?

Please post your code.

Me.Controlname.Undo will NOT highlight anything; it will erase whatever the
user put into the control, leaving it as it was prior to the user's opening
the record (either blank or with the previously existing data). My SelStart
code (NOT using Undo) will select what's there - but that's what you asked
for.

John W. Vinson [MVP]
 
Back
Top