Performing a Conditional statement for each record in a Continuous form (1 Viewer)

D

Dr Gregg

Guest
I'm using VB to change the value of a Text Label on a form if a certain condition is true on the Form_Load sub.

Code:
Code:
Private Sub Form_Load()

If Me!name.Value = "me" Then
   Label11.Caption = "lalala"
Else
   Label11.Caption = "nonono"
End If

End Sub

Now say, what I want it to do is for each record change Label11.Caption to lalala if the name field is me. If it isn't, then change Label11.Caption to nonono.



As you see, it sees that in the first record the name is 'me' so it changes Label11 to lalala. However, the next name is 'him' so I want the Label to be nonono. But it sets every single Label11 the same.



Now, in this instance the first record is 'him'. The code sees this and sets Label11 to nonono. However, in the record after the name is me - so I want it to be lalala. Except again, it sets every single Label11 to the same caption as the first one was.



I don't know how to do this Conditional Statement for every record on the form.
 

WayneRyan

AWF VIP
Local time
Today, 10:23
Joined
Nov 19, 2002
Messages
7,122
Dr Greg,

It might be a lot easier if you stop using reserved words like "Me" and "Name".

Get those out of the problem and things might resolve themselves.

Wayne
 

ChrisO

Registered User.
Local time
Today, 19:23
Joined
Apr 30, 2003
Messages
3,202
The ‘problem’ is that there is only one control named Label11 and when you change a property of that (singular) control all ‘instances’ of that control change. Incidentally, it’s not just a problem with Continuous Forms as it also happens in Single Forms.

To have a change made from record to record the change must be conditionally related to the data being displayed in that control or record and not directly to a property of that control.

And that can be difficult.

Regards,
Chris.
 

WayneRyan

AWF VIP
Local time
Today, 10:23
Joined
Nov 19, 2002
Messages
7,122
Thanks Chris,

I just saw the "Me"s and the "Name"s and gave up!

Wayne
 

ChrisO

Registered User.
Local time
Today, 19:23
Joined
Apr 30, 2003
Messages
3,202
You’re welcome Wayne but it can be difficult and Dr Gregg is not out of the ‘pickle’ just yet.

If it can be done it will need conditional formatting (and because I only use A97 I have a head start :D ) but we also need some of the underlying data to even give it a go.

What I think we need is a little demo, in A97 please, so all versions users can get their teeth stuck into it. It will probably be simpler in versions > A97 but Dr Gregg does not say what version is being used.

Could be interesting if it is A97… :eek:

Kind regards,
Chris.
 

MarkK

bit cruncher
Local time
Today, 02:23
Joined
Mar 17, 2004
Messages
8,186
Spoof the label using a textbox. Don't name the textbox "Name" since this will easily get confused with the ".Name" property of almost everything, including "Me.Name", since "Me" provides an object reference to the object in which code is currently running.
Set various properties of the textbox like Special Effect, Back Style, Locked, Enabled, so it looks and acts just like a label.
Set the Control Source property of the textbox to...
=iif([tbName] = "him", "lalala", "nonono")
 
D

Dr Gregg

Guest
Cheers lagbolt, that worked a treat.

(and I'm using 2000 by the way)
 

mresann

Registered User.
Local time
Today, 02:23
Joined
Jan 11, 2005
Messages
357
Although your current solution will work, the DataChange Event of the form is the place to include all code related to continuous forms' controls. Your code listed in the first post of the thread should work there.
 

Users who are viewing this thread

Top Bottom