tab control on unbound form

P

Phil

Hi,

I have an unbound form with a tab control and 6 pages.
I'm trying to stop the change of tabs if the user enters
information on a particular tab but does not save the
information (using a save button I've made) before moving
to the next tab. The tab change event looks like it
occurs after the tab changes, and I could not think of
another tab or control event that would work

Before I rework the form (probably using command buttons
and sub forms instead of a tab control and pages), does
anyone have any suggestions as to how I could make the
tab control work to my liking?

Thanks,
Phil
 
J

Jim Allensworth

Hi,

I have an unbound form with a tab control and 6 pages.
I'm trying to stop the change of tabs if the user enters
information on a particular tab but does not save the
information (using a save button I've made) before moving
to the next tab. The tab change event looks like it
occurs after the tab changes, and I could not think of
another tab or control event that would work

Before I rework the form (probably using command buttons
and sub forms instead of a tab control and pages), does
anyone have any suggestions as to how I could make the
tab control work to my liking?

What I do for that is to do a check for whatever it is that I want to
have occurred. And if it has not occured then I send them back to the
page where the unfinished business is, e.g.

If IsNull(Me.txtOrderNum) Then
'There is no current order so send the user back to the
'first page of the tab control.
Me.tabOrders.Pages(0).SetFocus
Exit Sub
Else
'send them to the proper page - and so on.


- Jim
 
P

Phil

-----Original Message-----


What I do for that is to do a check for whatever it is that I want to
have occurred. And if it has not occured then I send them back to the
page where the unfinished business is, e.g.

If IsNull(Me.txtOrderNum) Then
'There is no current order so send the user back to the
'first page of the tab control.
Me.tabOrders.Pages(0).SetFocus
Exit Sub
Else
'send them to the proper page - and so on.


- Jim

.


Thanks Jim - I tested something similar to this an it
seemed to work. I just need to give the user a message
after, not before, I reset the focus, so it looks like
the user hasn't left the first page.
 
P

Phil

For those curious few, here's the code that seems to
work...

Private Sub tabLabAdd_Change()
Dim ctl As Control
Dim valCount As Integer
Dim newPage As Integer
Dim oldPage As Integer

'first, save the values of the current page and the
new page
oldPage = Me.txtCurrentValue ' value of hidden text
box
newPage = Me.tabLabAdd

'set counter to zero
valCount = 0

'On the current page, determine whether or not any
unbound textbox values on the page have been "dirtied"
For Each ctl In Me.tabLabAdd.Pages(CInt
(oldPage)).Controls
'Check labels because I only know how to get the
control's parent's value
If ctl.ControlType = acLabel Then
If ctl.Parent.Value <> "" Or ctl.Parent.Value
<> Null Then
valCount = valCount + 1
End If
End If
'Now, if any parent control (the textbox) has a
value, tell user to save or clear it and exit out
If valCount > 0 Then
Me.tabLabAdd.Pages(CInt(oldPage)).SetFocus
'Needed because change event will run twice
once Set Focus is run in above line
If newPage <> oldPage Then
MsgBox "Page has been edited. Please
save information or clear form before moving " _
& "to another page. ",
vbOKOnly, "Please Save or Clear Information"
End If
Exit Sub
End If
Next
'If we are down here, old page was blank - assign the
new page value to the hidden textbox that tracks this
Me.txtCurrentValue = Me.tabLabAdd

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top