473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to set focus on field in tabbed form?

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

Apr 10 '06 #1
9 6414
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
"Mary" <mm**********@msn.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
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

Apr 11 '06 #2
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.

Apr 11 '06 #3
Br
Mary wrote:
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?
--
regards,

Br@dley
Apr 11 '06 #4
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
"Mary" <mm**********@msn.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
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.

Apr 11 '06 #5
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.

Apr 11 '06 #6
Tina,

I figured I was missing something!

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

Mary

Apr 11 '06 #7
you're welcome! :)
"Mary" <mm**********@msn.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Tina,

I figured I was missing something!

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

Mary

Apr 11 '06 #8
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

Apr 16 '06 #9
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
"tlyczko" <tl*****@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
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

Apr 16 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Heather | last post by:
I know Steve Lebans has code for changing colors of tabs/pages when active but the code is so complex I can't follow it to pick out the parts I need. I just want to make the current page name bold...
3
by: Steve Miles | last post by:
I've got a tabbed form with the 2nd tab containing a subform. I'm trying to avoid the need to use the mouse to set focus to the first field on the subform. I can use <CTRL><TAB> to open the 2nd...
4
by: Randy | last post by:
Hello all, I have a form with a text field (textBox1) on it. Apparently, textBox1.Focus() doesn't work when the form is initializing. I put this in the Constructor and also in the Load event for...
4
by: david.isaacks | last post by:
Is there a way on a form of making one field the default field such that as soon as you navigate to the form page, the cursor is sitting on that field ready for data to be entered.
3
by: hugo | last post by:
Hi, I have a function that I call from form fields using the OnKeyUp function to replace special caracters. Once this function has been called, it does not set the focus on the form field where...
0
by: jvitti | last post by:
I recently upgraded from Access 2000 to Access 2007 and I am having trouble with moving the focus from 1 form to another. While doing data entry if a similar claim is found the claim view form...
1
by: bbatson | last post by:
Hello, I've recently created a tabbed form. The forms within the tabbed form have command buttons that create reports based on queries that are driven by the forms (based on the !! setup). The...
3
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, How to make a tabbed form ? I tried to use Flowlayoutpanel and failed. Clara thank you so much for your help
2
by: bbatson | last post by:
Hello, I can't seem to figure out how to prevent a tabbed form from changing colors toward the bottom half of the form. See image below: http://img236.imageshack.us/img236/8652/postbz5.jpg ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.