Setting form properties

D

Dale DeWitt

I have a form that has a tab control (actually 10 tab
pages)... on each page I have a subform......

On the main form, I call a SQL function I wrote in SQL
2000, and set a field defined in the module I call, to
the value returned from the function.

Based on the value returned from the function, I need to
do the following:

Function SetFormStatus()
If gCoreMemberStatus = 1 Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
If gCoreMemberStatus = 2 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 3 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 4 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 5 Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
End Function

The thing I am getting hung up on is the fact that
the "ME." only refers to the main form, and not the
subforms. So I thought I would just drop the code into
each subform, but the form events do not fire the way
they do on the main form. I tried to put the code in the
forms.activate event, and the eventnever fires.

So I am thinking maybe I need to loop through the
controls on the main form setting the properties that
way, and Im just getting myself more confused.....

I need to be able to reference the tab control, and the
subform control, down to the form on the subform..... all
to lock down update privilges on the forms.

I hope I am not being to confusing..... In a nutshell, I
am looking at the role the user belongs to in the SQL
Database, and passing that back to the form..... That
determines what update rights a user has on the form.
Either full rights, no update rights, or partial rights
(update only certain fields)......

Any ideas ??
 
D

Dirk Goldgar

Dale DeWitt said:
I have a form that has a tab control (actually 10 tab
pages)... on each page I have a subform......

On the main form, I call a SQL function I wrote in SQL
2000, and set a field defined in the module I call, to
the value returned from the function.

Based on the value returned from the function, I need to
do the following:

Function SetFormStatus()
If gCoreMemberStatus = 1 Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
If gCoreMemberStatus = 2 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 3 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 4 Then
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
If gCoreMemberStatus = 5 Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
End Function

The thing I am getting hung up on is the fact that
the "ME." only refers to the main form, and not the
subforms. So I thought I would just drop the code into
each subform, but the form events do not fire the way
they do on the main form. I tried to put the code in the
forms.activate event, and the eventnever fires.

So I am thinking maybe I need to loop through the
controls on the main form setting the properties that
way, and Im just getting myself more confused.....

I need to be able to reference the tab control, and the
subform control, down to the form on the subform..... all
to lock down update privilges on the forms.

I hope I am not being to confusing..... In a nutshell, I
am looking at the role the user belongs to in the SQL
Database, and passing that back to the form..... That
determines what update rights a user has on the form.
Either full rights, no update rights, or partial rights
(update only certain fields)......

Any ideas ??

I doubt I have the complete picture, but why not generalize your
function so that you pass it the form object whose properties are to be
set; e.g., something like this:

'----- start of suggested revised code -----
Function SetFormStatus(frm As Form)

Select Case gCoreMemberStatus
Case 1
frm.AllowAdditions = True
frm.AllowDeletions = True
frm.AllowEdits = True
Case 2
frm.AllowAdditions = False
frm.AllowDeletions = False
frm.AllowEdits = False
Case 3
frm.AllowAdditions = False
frm.AllowDeletions = False
frm.AllowEdits = False
Case 4
frm.AllowAdditions = False
frm.AllowDeletions = False
frm.AllowEdits = False
Case 5
frm.AllowAdditions = True
frm.AllowDeletions = True
frm.AllowEdits = True
End Select

End Function

'----- end of suggested revised code -----

Then you could call this function 11 times from your main form, once for
the main form, and once for each subform:

SetFormStatus Me
SetFormStatus Me.sfSubform1.Form
SetFormStatus Me.sfSubform2.Form
SetFormStatus Me.sfSubform3.Form
SetFormStatus Me.sfSubform4.Form
SetFormStatus Me.sfSubform5.Form
SetFormStatus Me.sfSubform6.Form
SetFormStatus Me.sfSubform7.Form
SetFormStatus Me.sfSubform8.Form
SetFormStatus Me.sfSubform9.Form
SetFormStatus Me.sfSubform10.Form

In the above example, "sfSubform1" - "sfSubform10" are the names of the
10 subform *controls* on the tab pages, which may or may not be the
names of the actual form objects being displayed in those controls.
 
D

Dale DeWitt

Do I need to reference the tab controls at all ?? Im
unsure of the syntax..... Do I have to reference the
Main_Form, tab_Control, Subform_Control, and form on the
subform_Control ?? i always get mixed up with the
bangs ! and dots.

Sorry about the questions, Im more sure of myself with
SQL than I am with VB..... Thank you for your
assistance....
 
D

Dale DeWitt

Another question.... once I set the AllowEdit, etc, can I
override that with individual controls that I want to
open up for edit ??
 
D

Dirk Goldgar

Dale DeWitt said:
Do I need to reference the tab controls at all ?? Im
unsure of the syntax..... Do I have to reference the
Main_Form, tab_Control, Subform_Control, and form on the
subform_Control ?? i always get mixed up with the
bangs ! and dots.

No, the tab control is irrelevant to references to controls on the form.
Or rather, you can include the tab control and its pages in the
reference chain if you want, since the tab pages have Controls
collections, but it's not necessary because every control on the form is
a member of the form's Controls collection.
 
D

Dirk Goldgar

Dale DeWitt said:
Another question.... once I set the AllowEdit, etc, can I
override that with individual controls that I want to
open up for edit ??

You can't do that very easily. If you want to allow the user to edit a
particular control, you have to temporarily AllowEdits for the form
containing it, and then turn it back off again later.

An alternative to this approach is to leave AllowEdits set to True, but
set all bound controls' Locked properties to True. Then you can unlock
a particular control and lock it again without concerning yourself with
other controls or the form itself.
 
D

Dale DeWitt

Thank you Dirk, you have been very helpful !!

One other question...... On that same form, with the
subforms on the tab controls..... Whenever I display the
main form... the tab controls end up scrolling up under
the header area of the form... it doesnt happen on all
tabs, just on a few.... it originally scrolls up, then
once you pull it back down, you can click on a number of
the tabs just fine, but a few make the subform scroll up,
until you can not see the tabs at all..... Is there a way
to set the form position and make it stay ??

Dale.
 
D

Dirk Goldgar

Dale DeWitt said:
Thank you Dirk, you have been very helpful !!

One other question...... On that same form, with the
subforms on the tab controls..... Whenever I display the
main form... the tab controls end up scrolling up under
the header area of the form... it doesnt happen on all
tabs, just on a few.... it originally scrolls up, then
once you pull it back down, you can click on a number of
the tabs just fine, but a few make the subform scroll up,
until you can not see the tabs at all..... Is there a way
to set the form position and make it stay ??

Hmm, I've heard this reported and I'm trying to recall what was said
about it. IIRC, it happens as Access tries to ensure that all the
controls on the tab control are in view. You could try searching Google
Groups (http://groups.google.com), in the *.*access.* newsgroup
hierarchy, for messages on the subject. I think the solution involves
having a control, possibly even an infinitesimal one, high up on the
form, and sending the focus to that control in the appropriate event --
maybe the form's Current event or the tab control's Change event.
 

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

Similar Threads


Top