Code not recognising value in field

  • Thread starter Thread starter Julia Boswell
  • Start date Start date
J

Julia Boswell

Folks,

I have, what I'm sure is a really simple to fix problem, but it's driving me
nuts and I'm sure I'll kick myself when I realise what the problem is!

I have a form set up as a menu that has two commands cmdEdit and cmdRead.
cmdEdit opens form "frmAnticipated" with the controls unlocked and cmdRead
opens form "frmAnticipated" with most of the controls (but not all) locked.

For user benefit I've got labels on frmAnticipated to identify which mode
the form is in i.e. Read only or Edit mode. So the other thing cmdEdit and
cmdRead do is to set the value on a hidden field on frmAnticipated called
txtMode to either "EditMode" or "ReadOnly" respectively.

This all works fine, except when I try and reset the labels on
frmAnticipated based on the value in txtMode. My code on frmAnticipated goes
like this:

If Me.txtMode.Value = "EditMode" Then
Me.lblFormStatus.Caption = "This form is in edit mode"
Me.cmdSaveClose.Caption = "Save and Close"
Me.cmdUndoClose.Visible = True
Else
Me.lblFormStatus.Caption = "This form is in read only mode"
Me.cmdSaveClose.Caption = "Close"
Me.cmdUndoClose.Visible = False
End If

I've tried this code on the OnOpen, OnActivate and OnCurrent events and the
value is not recognised. I know it's something to do with order of events as
I tried to display the value in txtMode through a message box and I get the
message "Invalid Use of Null", however when the form finally does open and
if I make txtMode visible it has been set to the appropriate value.

When should I run this code?

Thanks in advance.

Julia
 
Julia,

You might include the code (the relevant piece each time) in the cmdEdit and
cmdRead code, right after the DoCmd.OpenForm statement, just replacing the
Me. keyword with an absolute form reference, e.g.:
Forms!frmName.lblFormStatus.Caption = "This form is in edit mode"
Forms!frmName.cmdSaveClose.Caption = "Close"
Forms!frmName.cmdUndoClose.Visible = False
(replacing frmName with the actual name of the form)

That way you may no longer require the hidden text box. Even if you need to
"know" the status for some other operation while the form is open, you can
always "read" it from the lblFormStatus caption or cmdSaveClose caption or
cmdUndoClose visible property.

HTH,
Nikos
 
Thanks for that! Good idea. It's funny isn't it, I'd got so stuck on
resolving the issue I had without tryin to work out if there was another way
to do this! Sometimes you just can't see the wood for the trees.

Julia
 
Back
Top