forms - open as read-only or normal - depends on the chose record

B

bizzybee

I want to know how I can program Access to open a form as read-only depending
on the result of the record choosen. Users select the record based on the
name of the customer. The form has to be opened in read-only if a date in
the record is not null. If the date-field is null , form should be opened
normal

How do I do this ?

Thanks for your help !
 
O

Ofer Cohen

Why do you open the form if the customer doesn't exist, instead of openning
in read only, check before you open the form if that customer exist, if not,
prompt a message and don't open the form

In the OnClick event of the button add something like


If DCount("*","[TableName]","[name of the customer] ='" & [name of the
customer] & "'") = 0 Then
MsgBox "Customer doesn't exist"
Else
Docmd.OpenForm ....
End If


Note: change the names to suit you mdb
 
M

Marshall Barton

bizzybee said:
I want to know how I can program Access to open a form as read-only depending
on the result of the record choosen. Users select the record based on the
name of the customer. The form has to be opened in read-only if a date in
the record is not null. If the date-field is null , form should be opened
normal


To lock the entire form, use code like:

Me.AllowEdite = False
Me.AllowDeletions = False

in the form's Current event.

If there are on of more controls that you need to use
regardledd of the date field being null or not, then you
need to identify each control that you want to lock. An
easy way to do that is to set the controls' Tag property to
something like LOCK and use code like:

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "LOCK" Then
ctl.Lock = Not IsNull(Me.datefield)
End If
Next ctl
 
B

bizzybee

MY question was not clear.

The customer exists ! That's not the point. But if a certain datefield is
used, the form should be opened as read-only or the record should be locked
for modifications. When the datefield is not yet filled up, users may modify
the record.

Hope my problem is clearer now ?
Bizzybee
 
B

bizzybee

Thanks for your answer but it doesn't work. I'm still a beginner so lets do
it step by step.

event : Click

First I open the form : docmd.openform ....
I set the filter so that the user can give input for the record to open in
the form

Then , depending a field in the record, the form must yes/no read only

I wrote

if me.datcombet is not null then
me.AllowEdite = false
me.allowdeletion = false
endif

But the event is not doing its job. the form opens but with the correct
record, but I get errormessage.


Whats wrong;

Bizzybee
 
M

Marshall Barton

Is Null is not legal VBA syntax. Use the IsNull function
instead:

If IsNull(Me.datcombet) Then
 

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