acCmdSubformDatasheetView - command not available (1 Viewer)

303factory

Registered User.
Local time
Today, 16:17
Joined
Oct 10, 2008
Messages
136
Hi

I'm trying to get my subform to switch between form view and datasheet view with the following commands:

DoCmd.RunCommand acCmdSubformDatasheetView
DoCmd.RunCommand acCmdSubformFormView

I'm getting the error:
'The command or action 'SubformDatasheetView' isn't available now.'

The command is called from a button on the parent form, allowdatasheetveiw on the subform and parent is set to yes.)

The strange thing on a different parent form with the same subform, the command works fine. I cant work out what the difference between the two circumstances are! Any suggestions?

Thanks
 

303factory

Registered User.
Local time
Today, 16:17
Joined
Oct 10, 2008
Messages
136
I've tried everything I can think of.. if I maximise the background and right click and do form -> datasheet view it works fine.. so no idea why I cant do this by code!

Could it be anything to do with the recordsource of the form?

On my form where the command works fine the subform is linked to the form by a field, and the parent form is linked to query.

On the form where the command doest work there is no direct link to the parent form, instead this code is used.
Code:
strSQL = "SELECT * FROM qryMESMS WHERE UniqueRef =" & gUniqueRef 
 Me.subfrmMESMS.Form.RecordSource = strSQL
 

missinglinq

AWF VIP
Local time
Today, 11:17
Joined
Jun 20, 2003
Messages
6,423
Have you set the focus to the subform before issuing your command?

Me.NameOfSubformControl.SetFocus
 

303factory

Registered User.
Local time
Today, 16:17
Joined
Oct 10, 2008
Messages
136
Have you set the focus to the subform before issuing your command?

Me.NameOfSubformControl.SetFocus

Fraid so tried that.. no change! There are several subforms on this page, with only one visible. Usually the command makes whichever one is visible into datasheet view.. but I've tried stripping it down until there is only one subform, setting focus, then doing the command. Still fails..
 

missinglinq

AWF VIP
Local time
Today, 11:17
Joined
Jun 20, 2003
Messages
6,423
I'm sorry, I missed your line:
On the form where the command doest work there is no direct link to the parent form, instead this code is used.

If there's no direct link, i.e. you do not have a Link Master Field/Link Child Field set up, you do not have a subform! That's what defines a subform! And hence there's no subform to switch views on.
 

303factory

Registered User.
Local time
Today, 16:17
Joined
Oct 10, 2008
Messages
136
I'm sorry, I missed your line:


If there's no direct link, i.e. you do not have a Link Master Field/Link Child Field set up, you do not have a subform! That's what defines a subform! And hence there's no subform to switch views on.

Right, I've stipped it down to one main form and one subform. The main form is linked to a query. The subform has a link master field / link child field set up to the main form. The results are being displayed as I would want them to be. Yet I am still getting the same problem :mad: this is driving me insane
 

303factory

Registered User.
Local time
Today, 16:17
Joined
Oct 10, 2008
Messages
136
well dont ask me why but if I put 'on error resume next' before the datasheetview command.. it works fine! not only do I not get a debug, the form changes to datasheet view as requested.
 

HairyArse

Registered User.
Local time
Today, 16:17
Joined
Mar 31, 2005
Messages
92
I'm having this exact same issue, and what's particularly annoying is that I've done exactly the same thing on a different form and it works just fine.

For the record, the subform doesn't have to be linked to the main form for you to be able to switch between data and form view - I say this because my other form on which it works is set up exactly that way.

I've tried setting focus on the subform first, I've tried on error resume next, but this serves only to suppress the error message, the form view doesn't ever actually change. There's got to be one little thing that I'm missing, but I can't find what it is.
 

HairyArse

Registered User.
Local time
Today, 16:17
Joined
Mar 31, 2005
Messages
92
I came across this thread as I was struggling to get the acCmdSubformDatasheet command to work as I constantly got the errors:

Run-time error '2046':
the command or action 'Formview' isn't available now

For anyone in the same situation, you need to ensure that on your Form Properties, under the Format Tab, that first of all, the Allow Datasheet View property is set to Yes, and that one of Allow Form View or Allow Layout is set to No as you can't set all of them to Yes.
 

isladogs

MVP / VIP
Local time
Today, 16:17
Joined
Jan 14, 2017
Messages
18,209
I came across this thread as I was struggling to get the acCmdSubformDatasheet command to work as I constantly got the errors:

Run-time error '2046':
the command or action 'Formview' isn't available now

For anyone in the same situation, you need to ensure that on your Form Properties, under the Format Tab, that first of all, the Allow Datasheet View property is set to Yes, and that one of Allow Form View or Allow Layout is set to No as you can't set all of them to Yes.

Yes you can....

 

Attachments

  • Capture.PNG
    Capture.PNG
    7.5 KB · Views: 491

Users who are viewing this thread

Top Bottom