Set the focus

G

Guest

I am trapping for a duplicate Container number. After the error is trapped I want to set the focus back to the field (Container) that has the duplicate value. This is written in Access 97. The problem is that the focus does not return to the appropriate field. The following is the code

Select Case Err.Numbe
Case 302
' Container # is a duplicat
strMSG = "Container #" & Me.Container & " is a duplicate." & Chr(10
strMSG = strMSG & "Please input a different Container #.
strOpt = vbOKOnl
strTtl = "ERROR-DUPLICATE CONTAINER #
strRes = MsgBox(strMSG, strOpt, strTtl
' Set the focus back to the Container fiel

* This is the problem area. It advances to the next field on the sub-form instea
* of returning focus to the container field

Forms!frmMemoHdr!frmMemoDetail.Form!Container.SetFocu

Case Els
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, cstrProcNam
End Selec
GoTo ExitHer
 
M

Marshall Barton

SHIPP said:
I am trapping for a duplicate Container number. After the error is trapped I want to set the focus back to the field (Container) that has the duplicate value. This is written in Access 97. The problem is that the focus does not return to the appropriate field. The following is the code:

Select Case Err.Number
Case 3022
' Container # is a duplicate
strMSG = "Container #" & Me.Container & " is a duplicate." & Chr(10)
strMSG = strMSG & "Please input a different Container #."
strOpt = vbOKOnly
strTtl = "ERROR-DUPLICATE CONTAINER #"
strRes = MsgBox(strMSG, strOpt, strTtl)
' Set the focus back to the Container field

* This is the problem area. It advances to the next field on the sub-form instead
* of returning focus to the container field.

Forms!frmMemoHdr!frmMemoDetail.Form!Container.SetFocus


Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, cstrProcName
End Select
GoTo ExitHere


The focus can not be moved in either the Before Update
event.

The way to do this kind of validation is to use the
BeforeUpdate event and set Cancel = True when you want to
prevent the focus from moving on to another control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top