How do you refer to a control on another form

D

DJW

When I open Form1 (frm1), I am trying to compare the caption value of a
label (Label19) located on Form2 (frm2) to the current date. I would like
to use a If/Then statement.

The current code I am trying to use does not work. I believe it is because
I am not referencing the caption value properly. Here is what I have as the
code on frm1:

Private Sub Form_Open(Cancel As Integer)

If Forms!frm2.Label19.Caption = Now() Then

Msgbox "Sell item today!"

End If

End Sub

Any help would sure be appreciated. Thank you.
 
L

Larry Linson

Now() is a builtin function that returns the current date _and_ time, down
to the second. Unless you are using Label Captions in a very unusual
manner, I would be very surprised if you ever got a match. Date() is a
builtin function that returns the current date.

But, just as an aside, it is unusual to use Labels for data storage. Did/do
you have some compelling reason to do so?

Oh, another thing: for you to retrieve any information from another Form,
that other Form has to be _open_ (if it isn't, you will not find it in the
Forms collection, either).

Larry Linson
Microsoft Access MVP
 

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