I want to inhibit editing of one text box based on the content ofanother

B

BobC

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub
 
F

fredg

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub


Code both the [Status] AfterUpdate event AND the Form's Current event:

Me.AllowEdits = [Status] = "Ship Requested"
 
B

BobC

I'm having a hard time with this...
Are you saying put the same equation in two locations?
I never saw two = signs in the same expression?

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub


Code both the [Status] AfterUpdate event AND the Form's Current event:

Me.AllowEdits = [Status] = "Ship Requested"
 
F

fredg

I'm having a hard time with this...
Are you saying put the same equation in two locations?
I never saw two = signs in the same expression?
The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub


Code both the [Status] AfterUpdate event AND the Form's Current event:

Me.AllowEdits = [Status] = "Ship Requested"

Did you place it in the 2 locations?
Did you write the expression exactly as I wrote it?
What happened?
 
B

BobC

I did as you said and placed it in the two locations.
It worked logically backwards from what I wanted, so I changed the
equation to:
Me.AllowEdits = [Status] <> "Ship Requested"
It now works great! dispite the fact that I still do not understand it!

THANK YOU VERY MUCH!!!!!!!!

Bob
I'm having a hard time with this...
Are you saying put the same equation in two locations?
I never saw two = signs in the same expression?
On Fri, 27 Nov 2009 23:07:21 -0500, BobC wrote:

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub


Code both the [Status] AfterUpdate event AND the Form's Current event:

Me.AllowEdits = [Status] = "Ship Requested"

Did you place it in the 2 locations?
Did you write the expression exactly as I wrote it?
What happened?
 
D

Douglas J. Steele

AllowEdits is a boolean field (i.e.: it accepts True or False).

[Status] = "Ship Requested" and [Status] <> "Ship Requested" are boolean
expressions (i.e.: they return True or False)

I usually add parentheses to make it a little clearer:

Me.AllowEdits = ([Status] <> "Ship Requested")

Note that this is exactly the same as

If [Status] <> "Ship Requested" Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BobC said:
I did as you said and placed it in the two locations.
It worked logically backwards from what I wanted, so I changed the
equation to:
Me.AllowEdits = [Status] <> "Ship Requested"
It now works great! dispite the fact that I still do not understand it!

THANK YOU VERY MUCH!!!!!!!!

Bob
I'm having a hard time with this...
Are you saying put the same equation in two locations?
I never saw two = signs in the same expression?

fredg wrote:
On Fri, 27 Nov 2009 23:07:21 -0500, BobC wrote:

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub


Code both the [Status] AfterUpdate event AND the Form's Current event:

Me.AllowEdits = [Status] = "Ship Requested"

Did you place it in the 2 locations?
Did you write the expression exactly as I wrote it?
What happened?
 
L

Linq Adams via AccessMonster.com

Fred's code, placed as he's advised, will do the job.

There were two problems with your code:

First, you followed

me.Status = "Ship Requested"

with a semi-colon, instead of a comma, which was the cause of the

'Expected: list separator or )'

error message.

Secondly, IIF() is intended to be used to populate a value into a field. It
would use syntax like this

Me.Textbox = IIF(Me.Status = "Ship Requested", "ThisValue", "ThatValue")

It cannot be use to set a form's property, as you tried to do.

As always when doing this kind of thing, you need to have some strategy in
place for dealing with the user incorrectly entering "Ship Requested" in the
Status field. And this will happen!
 
B

BobC

It is not clear to me why I place the expression in TWO locations?
And... By doing so, does it affect more than ONE text box?

Thank you for you explanation!
Bob
 
B

BobC

Thank you for your time in explaining the suntax and use of the IIF
function! I could swear that the syntax I read had a semicolon????

Can you explain why it needed to be placed in TWO locations and in doing
so how many text boxes it affects?

Thank You Again,
Bob
 
L

Linq Adams via AccessMonster.com

Placing it in the AfterUpdate event of the Status control will set the
AllowEdit Property as soon as the Status control has a value entered.

Placing it in the Form_Current event insures that when you move from one
record to another, the Property is set appropriately.

For example, if you ***only*** place it in the Status_AfterUpdate event, and
the value entered is "Ship Requested," the AllowEdits would be set to True.

If you then move to another record, where the value of Status is something
other than "Ship Requested," AllowEdits will still be set to Yes, because
nothing ha been done to check the current value of Status!

Having the code in the Form_Update event checks the value of Status as you
move to a new record and sets AllowEdits accordingly.
 
D

Douglas J. Steele

I was addressing your comment "It now works great! dispite the fact that I
still do not understand it!"

David was pointing out that my termininology was sloppy.
 

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