Hiding columns?

I

Ilan

[Access 2000]


I have a form with a subform which displays records in a datasheet. Two
of the columns in the datasheet do not need to be displayed, because they
have a default value, and I don't want the user to change this value. One
way to do this is by hiding the columns in the datasheet. Is this safe
enough? The user is free to unhide these columns, isn't he?

I would much prefer to hide these columns in the grid when I design the
form. I note that when designing the subform for the datagrid, I can
alter the invidividual properties of the 'fields' in the datasheet. One
such property is 'visible'. If I change the value of this property to 'no',
the field still appears in the datasheet in 'runtime'.

Does anyone have any suggestions?

Thanks

Ilan
 
D

Dirk Goldgar

Ilan said:
[Access 2000]


I have a form with a subform which displays records in a datasheet.
Two of the columns in the datasheet do not need to be displayed,
because they have a default value, and I don't want the user to
change this value. One way to do this is by hiding the columns in
the datasheet. Is this safe enough? The user is free to unhide
these columns, isn't he?

I would much prefer to hide these columns in the grid when I design
the form. I note that when designing the subform for the datagrid,
I can alter the invidividual properties of the 'fields' in the
datasheet. One such property is 'visible'. If I change the value of
this property to 'no', the field still appears in the datasheet in
'runtime'.

Does anyone have any suggestions?

If the columns have default values in the *table design*, you don't need
to have them on your form at all. If they're not on the form, they
won't appear in the form's datasheet and can't be unhidden.
 
I

Ilan

Thanks for this. I think I failed to give enough detail.

Perhaps it would be simplest to give an example:

I have a table called 'sailors' and another table called 'ports'. I also
have a table called 'girls'

tblSailor
ID

tblPort
ID

tblGirl
SailorFK
PortFK
GirlName

Now, what I want is a form for adding girls to a sailors port. I have form
with two combo-boxes for this purpose. First, the user selects the sailor
from the combobox, then the user selects the port. Then, I have a datasheet
which shows all the sailor's girls in the port. I want this datasheet to
display only the list of girls which the sailor has in this port. I also
want the user to be able to add new girls by only having to type the girl's
name.

The fields of the query are as follows:

qryGirls
SELECT SailorFK, PortFK
FROM tblgirls
WHERE SailorFK = cmbSailor AND PortFK=cmbPort

Now, the datasheet displays three fields: the sailor, the port and the girl.
To ensure that the user now enters girls only for the selected port and
sailor, I have set the default value of the qryGirls.SailorFK to cmbSailor,
and the default value of the qryGirls.PortFK to cmbPort. However, if I do
not hide these fields, the user is free to change these values.

How do I prevent him from doing so? Am I going about this in the right way?

Many thanks

Ilan

Dirk Goldgar said:
Ilan said:
[Access 2000]


I have a form with a subform which displays records in a datasheet.
Two of the columns in the datasheet do not need to be displayed,
because they have a default value, and I don't want the user to
change this value. One way to do this is by hiding the columns in
the datasheet. Is this safe enough? The user is free to unhide
these columns, isn't he?

I would much prefer to hide these columns in the grid when I design
the form. I note that when designing the subform for the datagrid,
I can alter the invidividual properties of the 'fields' in the
datasheet. One such property is 'visible'. If I change the value of
this property to 'no', the field still appears in the datasheet in
'runtime'.

Does anyone have any suggestions?

If the columns have default values in the *table design*, you don't need
to have them on your form at all. If they're not on the form, they
won't appear in the form's datasheet and can't be unhidden.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Ilan said:
Thanks for this. I think I failed to give enough detail.

Perhaps it would be simplest to give an example:

I have a table called 'sailors' and another table called 'ports'. I
also have a table called 'girls'

tblSailor
ID

tblPort
ID

tblGirl
SailorFK
PortFK
GirlName

Now, what I want is a form for adding girls to a sailors port. I
have form with two combo-boxes for this purpose. First, the user
selects the sailor from the combobox, then the user selects the port.
Then, I have a datasheet which shows all the sailor's girls in the
port. I want this datasheet to display only the list of girls which
the sailor has in this port. I also want the user to be able to add
new girls by only having to type the girl's name.

The fields of the query are as follows:

qryGirls
SELECT SailorFK, PortFK
FROM tblgirls
WHERE SailorFK = cmbSailor AND PortFK=cmbPort

Now, the datasheet displays three fields: the sailor, the port and
the girl. To ensure that the user now enters girls only for the
selected port and sailor, I have set the default value of the
qryGirls.SailorFK to cmbSailor, and the default value of the
qryGirls.PortFK to cmbPort. However, if I do not hide these fields,
the user is free to change these values.

How do I prevent him from doing so? Am I going about this in the
right way?

I love your example!

You're making it harder than it needs to be, assuming I've understood
your intentions correctly. Using the tables in your example, set the
recordsource of your datasheet subform to this SQL statement:

SELECT SailorFK, PortFK, GirlName FROM tblGirls;

Note that no sailor or port criteria are being applied.

Remove any default values you may have applied to the controls on the
subform. Delete from the subform (but not from its recordsource) any
controls that are bound to SailorFK and PortFK. Now these fields exist
in the recordsource, but not as controls on the form at all.

For the subform control on the main form, set these properties:

Link Child Fields: SailorFK;PortFK
Link Master Fields: cmbSailor;cmbPort

That's all. The subform will list, by name, only those girls for the
sailor and port that are currently selected on the main form, and a new
girl can be added for that sailor/port combination simply by typing her
name in the blank new record.
 

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