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

How to get focus on the main form from a sub form

Status
Not open for further replies.

dtippin

MIS
Mar 2, 2002
3
US
I'm exiting my form by using the windows X, I've validated some data in my beforeupdate event and I've found that I don't have the data elements I need filled in on my main form. I need to set focus back to a field on my main form...how do I do this forms![from name]![form field].setfocus gives me an error. How do I place myself back on the main form field automatically? Please help!
 
Are you returning focus to the control that called the form, or to a different control???
 
I have three fields on my main form. When I Click on the X at any point I validate all of those fields, they are all required, and I don't want to put that validation at the database level, so I validate those fields in the beforeupdate event...but if any of those three fields on the main form are not valid I want to set focus back to them and I sometimes want to do that from the subform...but it won't let me!
 
This is the beginning of my Before Update event
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then

intReturn = MsgBox("Do you want to save the changes?", vbYesNoCancel)
Select Case Response
Case vbYes
' do nothing
Case vbNo
' Undo the changes before exiting
Me.Undo
Exit Sub
Case vbCancel
' Cancel and return to the form
Cancel = True
End Select
End If



If IsNull([Feedyard]) Then
Msg = "Feedyard Must be Entered"
Style = vbOKOnly + vbCritical
Title = "Feedyard Validation"
Response = MsgBox(Msg, Style, Title)
[Feedyard].SetFocus
Cancel = True
Exit Sub
End If

....theres more validation.

I click the X button to close and if I choose no don't save...I exit the form just fine. If I choose to save the record I get I get the Feedyard must be entered message, when I click OK then I get this error.

"Can't more the focus to the control Feedyard. Runtime error 2110!

If I take the set focus out then it gives the message that it can't save this record. It's as if it is not seeing the cancel=True.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top