Limit access to tab control page with field

  • Thread starter ThomasK via AccessMonster.com
  • Start date
T

ThomasK via AccessMonster.com

Im trying to block users access to certain fields unless another field (combo
box) contains the word "complaint". The combo box "InspectionType" is on one
page (Inspection Information) of a tab control and all the fields that I dont
want users to access are on another page (Complaint Information) of the
control. I tried putting this into the On Click event of the tab on the
Complaint Information page, but it didn't do anything.

Private Sub Form_OnClick(Cancel As Integer)
If Me!InspectionType <> "Complaint" Then
MsgBox "If this is a Complaint then enter Complaint in the Inspection Type
field!"
Cancel = True
Me!InspectionType.SetFocus
End If
End Sub

My thought was that the page could not be accessed unless the InspectionType
was Complaint. It would take the focus back to the control until it was set.

Thanks for the help.
 
T

ThomasK via AccessMonster.com

Sorry, copied that code wrong, this is what I have::

Private Sub Complaint_Click()
If Me!InspectionType <> "Complaint" Then
MsgBox "If this is a Complaint then enter Complaint in the Inspection Type
field!"
Cancel = True
Me!InspectionType.SetFocus
End If
End Sub
 
C

Clifford Bass

Hi Thomas,

Use an After Update event on the combo box. When it indicates
complaint, unlock the appropriate fields. Otherwise, lock them. Or, if the
entire page where the fields reside contains only complaint information, you
can just make the tab page visible or invisible. Additionally, if
appropriate, you could clear the fields when the user changes the combo box
value from compaint to something else.

Hope that helps,

Clifford Bass
 
D

Dale Fye

I agree with Clifford.

I would use the combo boxes AfterUpdate event to either hide or display the
"Complaint Information" tab. Something like:

Private Sub cbo_InspectionType_AfterUpdate

me.tabcontrolname.pages("Complaint Information").visible =
(me.cbo_InspectionType = "Complaint")

End Sub

You would need to also put this line of code in the forms current event, so
that if you go to a record that has already been completed, the tab will show
if appropriate.

BTW, you can refer to either the name of the tab or the page index:
me.tabcontrolname.pages(2)

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
T

ThomasK via AccessMonster.com

This is what I tried, so far it seems to work. This code seemed easier for me
to understand. I'm not too experienced with visual basic. I used the after
update event like you susgested and also the form current event. Please let
me know if this is completely wrong.

Thanks for pushing me in the right direction.

Private Sub InspectionType_AfterUpdate()
If Me.InspectionType = "Complaint" Then
Me.Complaint.Visible = True
Else: Me.Complaint.Visible = False
End If
End Sub

Private Sub Form_Current()
If Me.InspectionType = "Complaint" Then
Me.Complaint.Visible = True
Else: Me.Complaint.Visible = False
End If
End Sub
 
D

Dale Fye

Looks good to me, although I prefer to put the Else action on a separate line.

If Me.InspectionType = "Complaint" Then
Me.Complaint.Visible = True
Else
Me.Complaint.Visible = False
End If

Once you have gotten used to VBA, the following line would make more sense
to you.

me.Complaint.Visible = (me.inspectiontype = "Complaint")

In this line, Access will evaluate the expression inside the ( ). If this
expression evaluates to True, then the me.Complaint.Visible = True. If it
evaluates to False, then me.Complaint.Visible = False.

When you write a lot of code, you get used to these types of shortcuts.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
T

ThomasK via AccessMonster.com

Thanks for your help! VBA is still amazing and interesting to me. It's like a
puzzle sometimes, but fun to play with. I can see how your example would be
easier if you had to write a lot of code.
Thanks again.


Dale said:
Looks good to me, although I prefer to put the Else action on a separate line.

If Me.InspectionType = "Complaint" Then
Me.Complaint.Visible = True
Else
Me.Complaint.Visible = False
End If

Once you have gotten used to VBA, the following line would make more sense
to you.

me.Complaint.Visible = (me.inspectiontype = "Complaint")

In this line, Access will evaluate the expression inside the ( ). If this
expression evaluates to True, then the me.Complaint.Visible = True. If it
evaluates to False, then me.Complaint.Visible = False.

When you write a lot of code, you get used to these types of shortcuts.
This is what I tried, so far it seems to work. This code seemed easier for me
to understand. I'm not too experienced with visual basic. I used the after
[quoted text clipped - 16 lines]
End If
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