Setting field properties

  • Thread starter Thread starter OD
  • Start date Start date
O

OD

Hi

Hi have a calendar that I fill in the day of the month, but what i would
like to do now is change the backgrounf color of those days.

On Load Event

Dim x As String
Dim i As Integer

Me.TitleLabel.Caption = varMonth + " " + CStr(varYear)
DoCmd.GoToControl "Text" + CStr(varStartDay) 'The day of the week to start
varStartDay = varStartDay - 1 'Because the index starts with 0

For i = 1 To varDays 'the number of days in the month
Me.Controls.Item(varStartDay) = i
[Text#].BackColor = vbWhite 'here is where in need to change the
background color of
each text box in the
for loop
varStartDay = varStartDay + 1
Next i

OD
 
On Sun, 9 Aug 2009 21:53:01 -0700, OD <[email protected]>
wrote:

I'm not following. Couldn't you simply change vbWhite to vbRed or some
other color?

-Tom.
Microsoft Access MVP
 
I have a form with boxes "TextBox" to make a calendar. I fill the boxes with
the days 1 thur 28 or 29 for febuary the rest of the months 1 thur 30 or 31
depending on the month.

The form will open with all of the textboxes with the back color set to
black. The for loop will place the number in the textbox and change the back
color to white, so the textboxes not used will be black and the rest will be
white.

varStartDay is 1 thur 6 ' Because the index starts with 0

Sunday = 0
Monday =1
etc.
Saturday = 6
If I try to assign a property to the current fielld can't use
[Text&varStartDay]
how do I refer to a field and set its properties.


Thanks
OD

Tom van Stiphout said:
I'm not following. Couldn't you simply change vbWhite to vbRed or some
other color?

-Tom.
Microsoft Access MVP

Hi

Hi have a calendar that I fill in the day of the month, but what i would
like to do now is change the backgrounf color of those days.

On Load Event

Dim x As String
Dim i As Integer

Me.TitleLabel.Caption = varMonth + " " + CStr(varYear)
DoCmd.GoToControl "Text" + CStr(varStartDay) 'The day of the week to start
varStartDay = varStartDay - 1 'Because the index starts with 0

For i = 1 To varDays 'the number of days in the month
Me.Controls.Item(varStartDay) = i
[Text#].BackColor = vbWhite 'here is where in need to change the
background color of
each text box in the
for loop
varStartDay = varStartDay + 1
Next i

OD
 
Probably something like the following assuming your controls are named Text1
to Text38 (or whatever upper limit you have chosen)

Me.Controls("Text" & (i + varStartDay)).BackColor = vbWhite

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I have a form with boxes "TextBox" to make a calendar. I fill the boxes with
the days 1 thur 28 or 29 for febuary the rest of the months 1 thur 30 or 31
depending on the month.

The form will open with all of the textboxes with the back color set to
black. The for loop will place the number in the textbox and change the back
color to white, so the textboxes not used will be black and the rest will be
white.

varStartDay is 1 thur 6 ' Because the index starts with 0

Sunday = 0
Monday =1
etc.
Saturday = 6
If I try to assign a property to the current fielld can't use
[Text&varStartDay]
how do I refer to a field and set its properties.


Thanks
OD

Tom van Stiphout said:
I'm not following. Couldn't you simply change vbWhite to vbRed or some
other color?

-Tom.
Microsoft Access MVP

Hi

Hi have a calendar that I fill in the day of the month, but what i would
like to do now is change the backgrounf color of those days.

On Load Event

Dim x As String
Dim i As Integer

Me.TitleLabel.Caption = varMonth + " " + CStr(varYear)
DoCmd.GoToControl "Text" + CStr(varStartDay) 'The day of the week to start
varStartDay = varStartDay - 1 'Because the index starts with 0

For i = 1 To varDays 'the number of days in the month
Me.Controls.Item(varStartDay) = i
[Text#].BackColor = vbWhite 'here is where in need to change the
background color of
each text box in the
for loop
varStartDay = varStartDay + 1
Next i

OD
 
Thanks thats what I was looking for.

OD

JimBurke via AccessMonster.com said:
Try

Me.Controls("Text" & varstartday).BackColor = ...

This assumes the actual control names are Text1, Text2, etc.
I have a form with boxes "TextBox" to make a calendar. I fill the boxes with
the days 1 thur 28 or 29 for febuary the rest of the months 1 thur 30 or 31
depending on the month.

The form will open with all of the textboxes with the back color set to
black. The for loop will place the number in the textbox and change the back
color to white, so the textboxes not used will be black and the rest will be
white.

varStartDay is 1 thur 6 ' Because the index starts with 0

Sunday = 0
Monday =1
etc.
Saturday = 6
If I try to assign a property to the current fielld can't use
[Text&varStartDay]
how do I refer to a field and set its properties.

Thanks
OD
I'm not following. Couldn't you simply change vbWhite to vbRed or some
other color?
[quoted text clipped - 26 lines]
 
Thanks thats what I was looking for.

OD

John Spencer said:
Probably something like the following assuming your controls are named Text1
to Text38 (or whatever upper limit you have chosen)

Me.Controls("Text" & (i + varStartDay)).BackColor = vbWhite

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I have a form with boxes "TextBox" to make a calendar. I fill the boxes with
the days 1 thur 28 or 29 for febuary the rest of the months 1 thur 30 or 31
depending on the month.

The form will open with all of the textboxes with the back color set to
black. The for loop will place the number in the textbox and change the back
color to white, so the textboxes not used will be black and the rest will be
white.

varStartDay is 1 thur 6 ' Because the index starts with 0

Sunday = 0
Monday =1
etc.
Saturday = 6
If I try to assign a property to the current fielld can't use
[Text&varStartDay]
how do I refer to a field and set its properties.


Thanks
OD

Tom van Stiphout said:
I'm not following. Couldn't you simply change vbWhite to vbRed or some
other color?

-Tom.
Microsoft Access MVP


Hi

Hi have a calendar that I fill in the day of the month, but what i would
like to do now is change the backgrounf color of those days.

On Load Event

Dim x As String
Dim i As Integer

Me.TitleLabel.Caption = varMonth + " " + CStr(varYear)
DoCmd.GoToControl "Text" + CStr(varStartDay) 'The day of the week to start
varStartDay = varStartDay - 1 'Because the index starts with 0

For i = 1 To varDays 'the number of days in the month
Me.Controls.Item(varStartDay) = i
[Text#].BackColor = vbWhite 'here is where in need to change the
background color of
each text box in the
for loop
varStartDay = varStartDay + 1
Next i

OD
 
Actually, + can be used for concatenation in VBA. Be aware, though, that it
is different than using & for concatenation.

+ propagates Nulls, & doesn't.

That means that "abc" + Null or Null + "abc" will result in Null, whereas
"abc" & Null or Null & "abc" will result in "abc".

There are legitimate uses for this difference. For example, if you're
storing FirstName, Initial and Surname as separate fields, you can use
FirstName & (" " + Initial + ".") & (" " + Surname) to return Douglas J.
Steele if Initial is present, or Douglas Steele if it isn't.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JimBurke via AccessMonster.com said:
By the way, you may have just made a mistake when you posted your code,
but
'&' is used for concatenation, not '+'. I saw that you had + in some of
your
code - that's used in some languages, but not in VBA.
Thanks thats what I was looking for.

OD
[quoted text clipped - 29 lines]
 
Back
Top