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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuouis form - new record set focus to particular field?

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I have a contiuous form where the user can add new records to it. On it I have some validation on some of the fields that if a [ProjID] is null on this new record and the attmpt to fill in other feilds first then the user is prompted to select something in [projID] first. but when I try to set focus to the ProjID feild i get

error 2108 = u must save the field before you can execute gotofunction or set focus

The code I am using is below...
Code:
If Me.NewRecord = True And IsNull(Me.ProjID) Then
    Me.PersID.Undo
    MsgBox "Please select a Project before continuing.", vbInformation + vbOKOnly, "Add New"
    Cancel = True
    Me.ProjIDNo.SetFocus
End If
 

Hi neemi,

- In which event did you wrote the above code?

Me.ProjIDNo.SetFocus
- Why do you need this line? after 'Undo' and/or 'Cancel', the focus should stay in the current control?

Ja

 
Hi,

It might be that if 'Cancel=True', Access wont let you 'set focus' to another control. The thing is, that if you cancel the event, it's intended to keep focus in the same control, so you don't need to set focus.

Well, your problem might be, what if the user 'skips' the ID-field, and now you don't want to let him entering any data without entering a ID first. maybe that's why you want to send him back to the ID-control.

In this place, I would make sure that he should never be able to leave the ID-control. and that, by putting the validation code in the On Enter event from whatever control, and if ID isn't ok, then set focus back to the ID-control.

(by the way: in which 'BeforeUpdate' event you entered your code? the form's, or the control's? I think that in the form's 'BeforUpdate', you do can set focus to any control.)

Helpful?
Ja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top