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

A Procedure in a SubForm That Works Correctly ONLY Once

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
Good afternoon, folks. I have been looking at this procedure for three or four days now and I can not see what is wrong with this procedure. I have a form with four checkboxes on it and a subform, I want to have at least one or more of the checkboxes check before I can enter data in the subform. This procedure works great the first time, but if you return to the subform, without checking one of the checkboxes, you can now enter data in the subform, instead of getting booted out of the subform again. Here is the procedure:
Public Sub PartNumber_GotFocus()
With Me
If (.Parent.TypeNumber <> 500) Then
If (.Parent.Check206 + .Parent.Check208 + .Parent.Check210 + .Parent.Check227 = 0) Then
MsgBox &quot;Please Check at Least One Checkbox Before Entering a Part Number or Cancel ECN.&quot;
.Parent.Check206.SetFocus
Else
.PartNumber.SetFocus
.Parent.[PartNumber(s)_Label].ForeColor = 33023
End If
Else
.PartNumber.SetFocus
.Parent.[PartNumber(s)_Label].ForeColor = 33023
End If
End With
End Sub
Can anyone see what I am doning wrong? Why does it work the first time and not again? Thank you in advance to anyone who can answer this problem for me.
 
[tt]
Hi:

I think your procedure works only once because it is triggered only once.

Public Sub PartNumber_GotFocus()
triggers your procedure the first time. What is PartNumber_GotFocus?

Once you determine that no selection has been made among the checkboxes, you display the Msg and then move the focus back to Check206. There's nothing here that will trigger the procedure again. You've got to reactivate the form...I'm trying to think how you do this. I'll get back to you unless you figure it out, or it snaps into someone else's brain.

See ya' soon.[/tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7, on the way to 6, and beyond!
Webmaster: www.rentdex.com[/tt]
 
Thanks for the response, Gus. PartNumber is the name of a field in the subform where I am going to enter data, in this case part numbers. GotFocus is the name of the event, there is one thing that I must state here, this is for new ECN's ONLY, I have several other data fields that MUST be filled in before I can save this ECN. There is a procedure that checks to see if the data has be filled in before I can save and exit the form. I was trying to make it fool-proof and maybe this may kill me. What you were say about not resetting is my worst nightmare come true, and that is what I suspected. Hopefully, you or someone will know the work-around on this problem, it is my last bug, I hope, before going on-line. Thanks again, I appreciate the help.
 
[tt]
Ok.

You could put your procedure in the OnGotFocus event of the control that gets the focus immediately after the check boxes.

Or, you could make this inspection before the form is closed by putting it in the OnExit event of the form.

I hope that helps you.[tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7, on the way to 6, and beyond!
Webmaster: www.rentdex.com[/tt]
 
[tt]
Read your original post again. Looks like this check is the last thing that happens before you go to the subform. You could require a button push on the main form before going to the subform and make your inspection in the OnClick event of the button on the main form.[/tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7, on the way to 6, and beyond!
Webmaster: www.rentdex.com[/tt]
 
What I suspect that is happening is that you are leaving the subform which contains the PartNumber control. Specifically, you are going back to the Parent form which contains the Checkboxes. However, a control on a subform does not lose focus because you leave the subform and return to the main form. Although the subform is no longer active, the PartNumber control is still the Active Control on the subform. Therefore, when you return to the PartNumber control on the subform, the GotFocus event does not fire, because with respect to the subform, PartNumber never lost the focus.

The easiest solution is to change the focus on the subform to some other control (buttons are convenient for this) before returning to the parent form by setting the focus to one of it's checkboxes.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Another possibility is to use the PartNumber_Enter() event for this routine as I believe, but not 100% sure, that even tho the GotFocus will not fire upon return to the subform, I think the Enter event still does.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you for the responses.
Gus, you are right about the way things happen, but I was trying to keep this simple, with just two buttons, save and cancel. Trust me on this one, the fewer the choices/buttons the better off I will be. A dozen people will have access to this and wheter or not I like it, they will try and use it. Several are computer phobics.
CajunCenturion, I tried moving the procedure to the field's Enter event, and that was really bad. Fore some reason, the second the created a new ECN, the form opened and the Checkbox message pop-up, I tried setting focus on one of the checkboxes, but that had one effect either. I also tried using the subforms on focus event and its' on enter event, there it never gave me the message. So I return it to the text field on focus event.
So close to the end, yet so far away. Any other ideas? I will try anything. Thank you again for the assistance, I really appreciate it.
 
Bingo, I got it working. Moved the procedure to the textbox BeforeUpdate event and added and Me.Undo and it works. Thanks one and all and have a great day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top