use control value in form caption

A

Angi

I thought there was a way to do this, but I'm either wrong or forgot
how to.

I'm trying to put the Company id in the title bar of a form using the
caption. It's not working. It's ignoring my code for the caption.
Can this be done?

Private Sub Form_Open(Cancel As Integer)
If (Not IsNull(Me.OpenArgs)) Then
Me!CoID.DefaultValue = Me.OpenArgs
Me.Caption = "Notes for " & Me![CoID]
End If

End Sub
 
M

Marshall Barton

Angi said:
I thought there was a way to do this, but I'm either wrong or forgot
how to.

I'm trying to put the Company id in the title bar of a form using the
caption. It's not working. It's ignoring my code for the caption.
Can this be done?

Private Sub Form_Open(Cancel As Integer)
If (Not IsNull(Me.OpenArgs)) Then
Me!CoID.DefaultValue = Me.OpenArgs
Me.Caption = "Notes for " & Me![CoID]
End If

End Sub


Control value are not available in the Open event.

Why do you save OpenArgs in the control's DefaultValue
property and try to set the Coption form it's Value
property?
 
A

Angi

What about the OnCurrent event?? Any event?? I tried setting the form
caption to Notes for & [coid] but that's exactly what the caption was
then.

The honest answer is because that's what this group told me to do. The
other answer is because CoID is a hidden field and the person doesn't
see it. Did I understand your question right??
 
F

fredg

I thought there was a way to do this, but I'm either wrong or forgot
how to.

I'm trying to put the Company id in the title bar of a form using the
caption. It's not working. It's ignoring my code for the caption.
Can this be done?

Private Sub Form_Open(Cancel As Integer)
If (Not IsNull(Me.OpenArgs)) Then
Me!CoID.DefaultValue = Me.OpenArgs
Me.Caption = "Notes for " & Me![CoID]
End If

End Sub

What do you expect to see in the Form Caption? The value of [CoID] or
the DefaultValue?

The way your code is written, the CoID default value is the OpenArgs
value, but the caption will be the actual value stored in the very
first record's CoID field of the opened form, whatever it is.

If you want to display the openargs value then change that last line
to:
Me.Caption = "Notes for " & Me.OpenArgs

Note: If the [CoID] is a text datatype, then use:
Me!CoID.DefaultValue = chr(34) & Me.OpenArgs & chr(34)
 
M

Marshall Barton

Angi said:
What about the OnCurrent event?? Any event?? I tried setting the form
caption to Notes for & [coid] but that's exactly what the caption was
then.

The honest answer is because that's what this group told me to do. The
other answer is because CoID is a hidden field and the person doesn't
see it. Did I understand your question right??


No, not really.

What I was leading up to was using:

Me.Caption = "Notes for " & Me.OpenArgs
or
Me.Caption = "Notes for " & Me!CoID.DefaultValue

All I was trying to point out is that using the Value
property as you did seemed more than a little strange to me,
but John summarized the issue much better than I did.
 
A

Angi

Just FYI...I put this in the OnCurrent event and it works.

me.caption = "Notes for" & me.coid

Thanks for all your help!!
 

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

Similar Threads


Top