Une piste ...Mais les explications en anglais...Founies par un MS Access MVP sur Usenet
Source : http://www.tech-archive.net/
> I have a form that I use for order entry and from my frmmain I can
> open the form in edit mode (with a password) or read-only mode.
> The code that I use to open the form in read only mode is as
> Private Sub Command9_Click()
> DoCmd.OpenForm FormName:="frmOrders", DataMode:=acFormReadOnly ',
> End Sub
> The issue that I am having is that one of my controls on my form is a
> cbolookup that I have set up to search my frmoders, but with the
> above code, it is read only and therefore I cannot search.
> Does anyone have any suggestions?
Unfortunately, when a form is read-only, even the unbound controls on it
are read-only. Instead of opening it read-only, you may want to pass an
argument via OpenArgs to tell it that it should be "Read-Only". Then
let code in the form's Open event detect this argument and set all bound
controls to Locked=Yes.
Dirk Goldgar, MS Access MVP
Thanks for the info, I have copied the code into where it belongs in my db.
for the "Public Function fncLockUnlock" code, what do I name the module and
how and where do I call the module from?
"Dirk Goldgar" wrote:
> "Brook" <Brook@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > Dirk,
> > Thanks for the post.
> > I have never used OpenArgs before? I have over 30 controls on my
> > form, would I have to add each of them as locked or unlocked?
> If you want to lock/unlock all bound controls on the form, you can use
> code like this:
> '----- start of code -----
> Public Function fncLockUnlockControls(frm As Form, LockIt As Boolean)
> ' Lock or unlock all data-bound controls on form <frm>,
> ' depending on the value of <LockIt>: True = lock; False = unlock.
> On Error GoTo Err_fncLockUnlockControls
> Const conERR_NO_PROPERTY = 438
> Dim ctl As Control
> For Each ctl In frm.Controls
> With ctl
> If Left(.ControlSource & "=", 1) <> "=" Then
> .Locked = LockIt
> End If
> End With
> Skip_Control: ' come here from error if no .ControlSource property
> Next ctl
> Exit Function
> If Err.Number = conERR_NO_PROPERTY Then
> Resume Skip_Control
> MsgBox "Error " & Err.Number & ": " & Err.Description
> Resume Exit_fncLockUnlockControls
> End If
> End Function
> '----- end of code -----
> That function would be saved in a standard module.
> Then you'd have code in the form's Open event like this:
> '----- start of code for Open event -----
> Private Sub Form_Open(Cancel As Integer)
> Dim strArgs As String
> strArgs = Me.OpenArgs & vbNullString
> If strArgs = "ReadOnly" Then
> fncLockUnlockControls Me, True
> End If
> End Sub
> '----- end of code for Open event -----
> And in the code where you open the form, you'd write something like
> DoCmd.OpenForm "YourFormName", OpenArgs:="ReadOnly"
> Dirk Goldgar, MS Access MVP