Properties set in code don't stick

D

Dave Hoder

I'm using this code to go to a datasheet view in my form. I shouldn't be able
to edit anything in datasheet view (edits are allowed in form view) but all
my combo boxes still allow edits as well as some text fields while others
don't. If I briefly switch to Design View & back all seems well & no edits
are possible. Any ideas on how to make the properties stick?

Private Sub cmdDatasheet_Click()
On Error GoTo Err_cmdDatasheet_Click
Dim Response As Integer
If Me.Dirty = True Then 'If anything has changed prompt to save
Response = MsgBox("Would you like to save your changes?", vbYesNo,
"Save Changes?")
If Response = vbYes Then
cmdSave_Click
Else: DoCmd.RunCommand (acCmdUndo)
End If
End If

Me.ViewsAllowed = 2 'Allow Datasheet view
Me.AllowEdits = False 'Don't allow changes in Datasheet view
Me.AllowAdditions = False
Me.AllowDeletions = False
DoCmd.RunCommand (acCmdDatasheetView) 'Switch to datasheet view
DoCmd.Maximize

Exit_cmdDatasheet_Click:
Exit Sub

Err_cmdDatasheet_Click:
MsgBox Err.Description
Resume Exit_cmdDatasheet_Click

End Sub
 
D

Damian S

Hi Dave,

Where are you setting the values to false in the first place? eg: Do you
have an on current event that sets the AllowEdit, AllowAdditions etc?

Damian.
 
D

Dave Hoder

Hi Damian
Sorry I don't understand your question. The button click on the form should
change the values to false before switching to datasheet view.
 
D

Dave Hoder

Well I figured out the answer. Changing the view causes the properties to
reset to their defaults. Changing the order of execution seems to have solved
the problem:

Me.ViewsAllowed = 2 'Allow datasheet view
DoCmd.RunCommand (acCmdDatasheetView) 'Switch to datasheet view
Me.AllowEdits = False 'Don't allow changes in Datasheet view
Me.AllowAdditions = False
Me.AllowDeletions = False
DoCmd.Maximize
 

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

Need help modifying code 0
Help with allowedits 3
Allow Edits to Subform 2
Mandatory Fields 4
error 2499 9
Allow Edits 2
Do not want subform to update 16
Changing View from From to Datasheet in VBA 0

Top