Subform data sheet and form view

Hi all

I have a Subform that is viewed sometimes in data sheet and sometimes in form view. When switching is there any way of hiding (programmatically) some of the columns in data sheet view.

These controls would be hidden in form view and hold information that is not necessary to the user
Derek BrownMDAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
best to upload the db if you can ...
mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You can use the ColumnHidden property

EG:

Me.YourTextBoxName.ColumnHidden = True ' False

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
see image
Capture1.gif
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Derek BrownMDAuthor Commented:
I tried this in the subform's onchange event and in the main form's on change event

Me.QCW1.ColumnHidden = True
Me.QCW2.ColumnHidden = True
Me.QCW3.ColumnHidden = True
Me.QCW4.ColumnHidden = True
Me.QCW5.ColumnHidden = True
Me.QCW6.ColumnHidden = True

and various versions of the following again in both on change events. Details being the name of the subform

[Details].Form![QCW1].ColumnHidden = True
[Details].Form![QCW2].ColumnHidden = True
[Details].Form![QCW3].ColumnHidden = True
[Details].Form![QCW4].ColumnHidden = True
[Details].Form![QCW5].ColumnHidden = True

I must be doing something wrong?
[Details].Form![QCW6].ColumnHidden = True


0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Forms don't have a On Change event, so I'm not quite following ....

mx
0
 
Derek BrownMDAuthor Commented:
Sorry I mean on view change event

Capture.JPG
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Umm ... that Event is not what it implies.  It deals with Pivot Table stuff (I think) ... as do all the events in that immediate area.

So, on your main form ... you will need a button, that toggles between the two views

DoCmd.RunCommand acCmdDatasheetView

 DoCmd.RunCommand acCmdFormView

And probably toggle the Button Caption property ... to correspond with view switching.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
And you will probably need to Set Focus to the Subform Control

Me.YourSubFormControlName.SetFocus

prior to executing the DoCmd line.  And of course, the code to hide/unhide the columns.

mx
0
 
Derek BrownMDAuthor Commented:
I have noticed that column hidden does not seem to apply to a bound control. Could this be the problem? Applies to list
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Column Hidden only applies IN datasheet view ... and you must refer to the Name of the Control.
In Form View, you will use the Visible Property

See my posts above this also.

mx
0
 
Derek BrownMDAuthor Commented:
Good greif It apears that I cannot even manage to set the focus without an hour work. It is not even an option in the expression builder.
Project is main form details is sub.  I get command or action is not available now on run command???
Private Sub Toggle_Click()
    Forms![ProjectForm]![Details].SetFocus
    [Details].SetFocus
If Toggle = 2 Then
    DoCmd.RunCommand acCmdDatasheetView
Else
    DoCmd.RunCommand acCmdFormView
End If
End Sub
0
 
Derek BrownMDAuthor Commented:
Sorry had Details.set focus twice.
Good greif It apears that I cannot even manage to set the focus without an hours work. It is not even an option in the expression builder.
Project is main form details is sub.  I get command or action is not available now on run command???
Private Sub Toggle_Click()
    Forms![ProjectForm]![Details].SetFocus
If Toggle = 2 Then
    DoCmd.RunCommand acCmdDatasheetView
Else
    DoCmd.RunCommand acCmdFormView
End If
End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Not sure what's up.  What you are doing is a bit ... um, unusual.

Can you upload the db and I will try to look at it later ... give details as to where things are at.

mx
0
 
Derek BrownMDAuthor Commented:
Hi Got this from 'tinternett

If Toggle = 2 Then
    DoCmd.RunCommand acCmdSubformDatasheetView
Else
    DoCmd.RunCommand acCmdSubformFormView
End If
0
 
Derek BrownMDAuthor Commented:
Hi

It's 3.19 am here. I will send it tomorrow.

That code works well and I havent managed to break it yet.

Thanks.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Wait ... I'm confused. Sooo, it's working ?

mx
0
 
Derek BrownMDAuthor Commented:
Problem solved. Thanks for putting me on the right track.

The docmd subform thing works perfect but I am not sure what you would do if there were two subforms on one main.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.