Link to home
Start Free TrialLog in
Avatar of bfuchs
bfuchsFlag for United States of America

asked on

how can i change a forms view from normal to datasheet programatically?

Hi Experts,
I have a sub form that users would like to view it in both ways, meaning in datasheet view by default, but should have the option to switch to normal form view, now I am trying to avoid creating an extra form, is there a way to code this by a click of a button?
When I try running the code me.SubForm.Form.CurrentView=0, I get an error saying "This property is read-only and can't be set"
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bfuchs

ASKER

Hi als315,

Thanks for replying,

I just got a chance to test this in my environment (access 2000), and it says "acCmdSubformFormView" this is not a defined type.

I tried the following
    If Me.subForm1.Form.CurrentView = 1 Then
        Me.subForm1.SetFocus
        DoCmd.RunCommand 108
        btn0.Caption = "Form view"
    Else
        Me.subForm1.SetFocus
        DoCmd.RunCommand 462
        btn0.Caption = "Datasheet view"
    End If

Open in new window


And the first part did well, however the else part (462) is giving me an error "You cancelled the previous command", any idea how to overcome this problem?

Thanks,
Ben
Avatar of bfuchs

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for bfuchs's comment #a40308833

for the following reason:

Never mind, I got my answer in link below, thanks for pointing me to the right direction.

https://www.experts-exchange.com/questions/23949961/Application-RunCommand-acCmdSubformFormView-Causes-Runtime-error-2501.html
Avatar of bfuchs

ASKER

Never mind, I got my answer in link below, thanks for pointing me to the right direction.