Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / April 2006

Tip: Looking for answers? Try searching our database.

how to set focus on field in tabbed form?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mary - 10 Apr 2006 23:51 GMT
I have a tabbed form. Tab 1 has fields that are mandatory. I am trying
to validate that these fields are not null, and cancel  updating if any
of them are. The following code works, except the form closes instead
of setting focus to the null field. What am I doing wrong? Do I need to
refer to the tab name when I set focus? I sure would appreciate any
help!

Here is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.TherapyStartDate & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in Date!"
Me!TherapyStartDate.SetFocus
ElseIf Len(Me.TherapyStartTime & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in Start Time!"
Me!TherapyStartTime.SetFocus
ElseIf Len(Me.TherapyEndTime & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in End Time!"
Me!TherapyEndTime.SetFocus
End If
End Sub
tina - 11 Apr 2006 01:53 GMT
well, when the form closes, did you click a command button that runs a Close
command? or did you click the "X" button on the form's Title Bar (far right
corner at the top)? or are you saying the the form closes "out of the blue",
even though you made no attempt to close it?

hth

> I have a tabbed form. Tab 1 has fields that are mandatory. I am trying
> to validate that these fields are not null, and cancel  updating if any
[quoted text clipped - 20 lines]
> End If
> End Sub
Mary - 11 Apr 2006 01:56 GMT
I click on a command button to close, but if these fields are null, I
don't want it to close. I want it to remain on the current form and set
focus to the null field.
Br@dley - 11 Apr 2006 02:13 GMT
> I click on a command button to close, but if these fields are null, I
> don't want it to close. I want it to remain on the current form and
> set focus to the null field.

Try setting the focus to the tab page first, then the field on that page?
Signature

regards,

Br@dley

Mary - 11 Apr 2006 02:41 GMT
My tab page is named "Session".

I tried adding:

Me!Session.SetFocus

before the lines that set focus to the null fields. It closes anyway.

Thanks for your response.
tina - 11 Apr 2006 02:34 GMT
cancelling the BeforeUpdate event only cancels the write to the table, it
doesn't cancel the Close command. you need to explicitly save the record in
the Close button code, and then handle the error that will arise from the
cancelled update, so that the Close command never runs, as

   On Error GoTo Err_Handle

   DoCmd.RunCommand acCmdSaveRecord
   DoCmd.Close , , acSaveNo

Err_Exit:
   Exit Sub

Err_Handle:
   Select Case err.Number
       Case Not 2501
           MsgBox err.Number & "  " & err.Description, "Unknown error"
   End Select

hth

> I click on a command button to close, but if these fields are null, I
> don't want it to close. I want it to remain on the current form and set
> focus to the null field.
Mary - 11 Apr 2006 03:11 GMT
Tina,

I figured I was missing something!

That did the trick. Thank you so much for your help!

Mary
tina - 11 Apr 2006 04:46 GMT
you're welcome!  :)

> Tina,
>
[quoted text clipped - 3 lines]
>
> Mary
tlyczko - 16 Apr 2006 20:32 GMT
Can this code be used to ensure that a SUBFORM does not close without
having at least one record added via the subform and/or that the
SUBFORM cannot be closed if at least one or more fields in the subform
are not filled in???

Would one put this in the OnExit event of the subform??

Thank you, Tom
tina - 16 Apr 2006 23:36 GMT
no, you can't use the posted code in a subform, because you don't "close" a
subform - you close the main form that the subform is "sitting" on. see my
more detailed answer in your thread started this date and titled "Why is my
BeforeUpdate code not working??".

hth

> Can this code be used to ensure that a SUBFORM does not close without
> having at least one record added via the subform and/or that the
[quoted text clipped - 4 lines]
>
> Thank you, Tom
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.