A Question about making forms EDITABLE

yus786

I do OK
Local time
Today, 14:23
Joined
Jun 25, 2008
Messages
121
Hi

I have currently have

Private Sub Form_Load()
Me.Form.AllowEdits = False
End Sub

But this locks the whole form including my Search Box, and doesn't let me type anything in here

How can i exclude the Search Box?
thanks
 
Two things I can think off the hand:

1) Put your combobox on another form, and make that read-only form a subform.
2) I believe that if you make your recordsource read-only, you still should be able to use unbound combobox for searching. To make your recordsource read only, go to form's properties, select Recordsource under Data tab, then click the tiny button on right to open the Query Builder. Click on a empty gray area where you put the tables, then go to queries' properties. There should be something like "Recordset Type" which the default is "Dynaset". Change it to "Snapshot" will make it readonly. You will not need that VBA code anymore.
 
Thanks

I'm going with point 2 and it works fine.

However i need a command button that would then make the form EDITABLE.

I've been trying this (on the cmdbutton) but it wont work

Me.Form.RecordsetType = Dynaset

Any idea's?
 
You'd have to close your recordset and open a new one in order to change between different types. Google "changing recordsource of form runtime" for some snippets to do this.

Just exactly what are you trying to do by making form read-only with a button to toggle the state? There may be a better and easier solution if we knew a bit more about why you want to do this way.
 
You'd have to close your recordset and open a new one in order to change between different types. Google "changing recordsource of form runtime" for some snippets to do this.

Just exactly what are you trying to do by making form read-only with a button to toggle the state? There may be a better and easier solution if we knew a bit more about why you want to do this way.

Thanks

I have a dead simple DB

The form in question is read from one table.

When the user enters this form - i need to to be READ ONLY.

I then need an 'EDIT' cmd button that will allow the users to make changes.
 
But exactly, why do you want to force your users to click a button so they can edit the form? What will this accomplish, besides annoying your users?

That said, by far the most simplest way to implement this, and not confuse your users into clicking on a textbox that appears to be editable (we've been trained to treat anything that's white in background as editable, no?) would be to do something like this:

1) Add a unbound textbox. Set its height and width to zero. Name it "txtFocusHolder".

2) Add this code for the appropriate events, or if you need it for more than one event, just call the procedure which should be on the same form's module.

Code:
Private Sub EditToggle()

Dim ctl As Control

Me.txtFocusHolder.SetFocus

For Each ctl in Me.Controls
       If Not ctl.Name = "txtFocusHolder" Then
             ctl.Enabled = Not ctl.Enabled
             ctl.Locked = Not ctl.Locked
      End If
Next ctl

End Sub

You can call this procedure to flip between editable and uneditable state, and when you do so, all controls will change to gray, indicating that it's not editable.
 
I tried this but got the following message
 

Attachments

  • error1.jpg
    error1.jpg
    10.5 KB · Views: 121
It's telling you that you're trying to make it do something that it doesn't have. In other words, did you actually call the procedure? Is it in right events (e.g. you can't call the procedure to enable/disable controls in certain events, and I believe Load event doesn't have the controls available for modifying for example)
 
It's telling you that you're trying to make it do something that it doesn't have. In other words, did you actually call the procedure? Is it in right events (e.g. you can't call the procedure to enable/disable controls in certain events, and I believe Load event doesn't have the controls available for modifying for example)

Ah ok - i just tried it on a cmd button
 
So did it work?

Or if you're still getting the error, make sure you have your code like this:

Code:
Private Sub MyCommandbutton_OnClick()

Call EditToggle

End Sub

HTH
 
"Object doesn't support this method or property"

means that you're trying to set the Enabled/Locked properties of all controls on the form, including controls, such as labels, that don't have Enabled/Locked properties. You need to modify your code to only set these properties on controls that do have them. This should do that for the most common controls:

Code:
Private Sub EditToggle()

Dim ctl As Control

Me.txtFocusHolder.SetFocus

For Each ctl in Me.Controls
       If Not ctl.Name = "txtFocusHolder" Then
          If TypeOf ctl Is Textbox Or TypeOf ctl Is Combobox Or TypeOf ctl Is Listbox Or TypeOf Is Checkbox Then
             ctl.Enabled = Not ctl.Enabled
             ctl.Locked = Not ctl.Locked
          End If
      End If
Next ctl

End Sub
 
Ooo, now I remember why I had to check for the control types! :o

Missingling has it right.
 

Users who are viewing this thread

Back
Top Bottom