Read Only Form allow a search

G

Guest

Good Day All,

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 follows:3

Private Sub Command9_Click()
DoCmd.OpenForm FormName:="frmOrders", DataMode:=acFormReadOnly ',
WindowMode:=acDialog
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?

Thanks,

Brook
 
D

Dirk Goldgar

Brook said:
Good Day All,

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
follows:3

Private Sub Command9_Click()
DoCmd.OpenForm FormName:="frmOrders", DataMode:=acFormReadOnly ',
WindowMode:=acDialog
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.
 
G

Guest

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?

Thanks

Brook
 
D

Dirk Goldgar

Brook said:
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_fncLockUnlockControls:
Exit Function

Err_fncLockUnlockControls:
If Err.Number = conERR_NO_PROPERTY Then
Resume Skip_Control
Else
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"
 
G

Guest

Hi Dirk,

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?

Thanks,

Brook
 
D

Dirk Goldgar

Brook said:
Hi Dirk,

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?

Name the module anything you like, so long as it's not the same as the
name of the function (or any other public name in the database). I'd
suggest "basUtilities" or "modUtilities", with the idea that you may add
other procedures of general utility to it later.

You don't call the module itelf; you just call the function, as I
described in my earlier message:
 

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

Top