PC Review


Reply
Thread Tools Rate Thread

Create TextBox and Label loop using code

 
 
=?Utf-8?B?ZHJld2RhdmlzMQ==?=
Guest
Posts: n/a
 
      20th Jun 2005
Hello,

I was wondering how I would go about creating a loop that would generate a
specified number of TextBoxes or Labels in a report.

Thanks for your help!!!
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q3liZXJ3b2xm?=
Guest
Posts: n/a
 
      20th Jun 2005
I would say the easiest was would be a Do While loop. This can create the
specified number of boxes and labels and can also be set as a variable based
on an input box or can be static.

"drewdavis1" wrote:

> Hello,
>
> I was wondering how I would go about creating a loop that would generate a
> specified number of TextBoxes or Labels in a report.
>
> Thanks for your help!!!

 
Reply With Quote
 
=?Utf-8?B?ZHJld2RhdmlzMQ==?=
Guest
Posts: n/a
 
      20th Jun 2005
Could you please give me a code sample, including the code to create the
textbox/label? I am pretty new at VB and this would really help.

Thanks for your input!!!!!

"Cyberwolf" wrote:

> I would say the easiest was would be a Do While loop. This can create the
> specified number of boxes and labels and can also be set as a variable based
> on an input box or can be static.
>
> "drewdavis1" wrote:
>
> > Hello,
> >
> > I was wondering how I would go about creating a loop that would generate a
> > specified number of TextBoxes or Labels in a report.
> >
> > Thanks for your help!!!

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      20th Jun 2005
drewdavis1 wrote:
>Could you please give me a code sample, including the code to create the
>textbox/label? I am pretty new at VB and this would really help.
>
>>
>> "drewdavis1" wrote:
>> > I was wondering how I would go about creating a loop that would generate a
>> > specified number of TextBoxes or Labels in a report.



I have to say that if you are new to VB/VBA, then you are
getting off on the wrong foot about using controls.

The only time you would want to write a VBA procedure to
create controls is if you are writing a **design** time
wizard for yourself.

For a **runtime** operation, you should (manually or using
code) precreate all possible needed controls at **design**
time, then make them visible as needed at run time.

If you'll explain more about **what** you're trying to
accomplish (instead of the way you've thought to do it),
then maybe someone will be able to provide a better idea.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
=?Utf-8?B?Q3liZXJ3b2xm?=
Guest
Posts: n/a
 
      21st Jun 2005
Good point Marshall, I just assumed it was something he wanted to do based on
an in put on a form someplace. i.e. how many children the person has and
would create text box for that number.

"Marshall Barton" wrote:

> drewdavis1 wrote:
> >Could you please give me a code sample, including the code to create the
> >textbox/label? I am pretty new at VB and this would really help.
> >
> >>
> >> "drewdavis1" wrote:
> >> > I was wondering how I would go about creating a loop that would generate a
> >> > specified number of TextBoxes or Labels in a report.

>
>
> I have to say that if you are new to VB/VBA, then you are
> getting off on the wrong foot about using controls.
>
> The only time you would want to write a VBA procedure to
> create controls is if you are writing a **design** time
> wizard for yourself.
>
> For a **runtime** operation, you should (manually or using
> code) precreate all possible needed controls at **design**
> time, then make them visible as needed at run time.
>
> If you'll explain more about **what** you're trying to
> accomplish (instead of the way you've thought to do it),
> then maybe someone will be able to provide a better idea.
>
> --
> Marsh
> MVP [MS Access]
>

 
Reply With Quote
 
=?Utf-8?B?ZHJld2RhdmlzMQ==?=
Guest
Posts: n/a
 
      21st Jun 2005
What i'm trying to do is create a loop that will create a label for each day
of the month (1,2,3,etc) based upon the number of days in a month and display
them in a line at the top of the report.

"Cyberwolf" wrote:

> Good point Marshall, I just assumed it was something he wanted to do based on
> an in put on a form someplace. i.e. how many children the person has and
> would create text box for that number.
>
> "Marshall Barton" wrote:
>
> > drewdavis1 wrote:
> > >Could you please give me a code sample, including the code to create the
> > >textbox/label? I am pretty new at VB and this would really help.
> > >
> > >>
> > >> "drewdavis1" wrote:
> > >> > I was wondering how I would go about creating a loop that would generate a
> > >> > specified number of TextBoxes or Labels in a report.

> >
> >
> > I have to say that if you are new to VB/VBA, then you are
> > getting off on the wrong foot about using controls.
> >
> > The only time you would want to write a VBA procedure to
> > create controls is if you are writing a **design** time
> > wizard for yourself.
> >
> > For a **runtime** operation, you should (manually or using
> > code) precreate all possible needed controls at **design**
> > time, then make them visible as needed at run time.
> >
> > If you'll explain more about **what** you're trying to
> > accomplish (instead of the way you've thought to do it),
> > then maybe someone will be able to provide a better idea.
> >
> > --
> > Marsh
> > MVP [MS Access]
> >

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      21st Jun 2005
Then manually create 31 labels in the report's design. The
report's Open event can then make some of them invisible
depending on the month. For example,

Select Case Month(datevalue)
Case 4, 6, 9,11
Me("lbl31").Visible = False
Case 2
Me("lbl31").Visible = False
Me("lbl30").Visible = False
If Day(DateSerial(Year(datevalue), 2, 29)) <> 29 _
Then Me("lbl29").Visible = False
End If
End Select


drewdavis1 wrote:
>What i'm trying to do is create a loop that will create a label for each day
>of the month (1,2,3,etc) based upon the number of days in a month and display
>them in a line at the top of the report.
>
>"Cyberwolf" wrote:
>> Good point Marshall, I just assumed it was something he wanted to do based on
>> an in put on a form someplace. i.e. how many children the person has and
>> would create text box for that number.
>>
>> "Marshall Barton" wrote:
>>
>> > drewdavis1 wrote:
>> > >Could you please give me a code sample, including the code to create the
>> > >textbox/label? I am pretty new at VB and this would really help.
>> > >
>> > >>
>> > >> "drewdavis1" wrote:
>> > >> > I was wondering how I would go about creating a loop that would generate a
>> > >> > specified number of TextBoxes or Labels in a report.
>> >
>> >
>> > I have to say that if you are new to VB/VBA, then you are
>> > getting off on the wrong foot about using controls.
>> >
>> > The only time you would want to write a VBA procedure to
>> > create controls is if you are writing a **design** time
>> > wizard for yourself.
>> >
>> > For a **runtime** operation, you should (manually or using
>> > code) precreate all possible needed controls at **design**
>> > time, then make them visible as needed at run time.
>> >
>> > If you'll explain more about **what** you're trying to
>> > accomplish (instead of the way you've thought to do it),
>> > then maybe someone will be able to provide a better idea.
>> >
>> > --
>> > Marsh
>> > MVP [MS Access]
>> >


--
Marsh
MVP [MS Access]
 
Reply With Quote
 
=?Utf-8?B?ZHJld2RhdmlzMQ==?=
Guest
Posts: n/a
 
      21st Jun 2005
Thanks for your input, but that not exactly what i'm looking for. I'm sorry,
i guess i wan't clear enough. I'm working on a Gantt style calendar to
display a schedule one month at a time. I have everything working but the
last thing I want to do is to make they days of the month dynamic based on
the number of days in the month. The labels for the days of the month width
vaires based upon how many days since the entire width of all the days is a
fixed width. Below is a copy and paste of the code that i have written that
works, but is cumbersome to write and i was wondering if i could use a loop
instead:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Dim lngNumDays As Long
Dim lngDayLength As Long
lngNumDays = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
lngDayLength = Me.boxTimeLine2.Width / lngNumDays

Me.Date1.Height = Me.boxTimeLine2.Height
Me.Date1.Width = lngDayLength
Me.Date1.Top = Me.boxTimeLine2.Top
Me.Date1.Left = Me.boxTimeLine2.Left
Me.Date1.BorderStyle = 1
Me.Date1.TextAlign = 2

Me.Date2.Height = Me.boxTimeLine2.Height
Me.Date2.Width = lngDayLength
Me.Date2.Top = Me.boxTimeLine2.Top
Me.Date2.Left = Me.boxTimeLine2.Left + Me.Date1.Width
Me.Date2.BorderStyle = 1
Me.Date2.TextAlign = 2

Me.Date3.Height = Me.boxTimeLine2.Height
Me.Date3.Width = lngDayLength
Me.Date3.Top = Me.boxTimeLine2.Top
Me.Date3.Left = Me.boxTimeLine2.Left + Me.Date1.Width + Me.Date2.Width
Me.Date3.BorderStyle = 1
Me.Date3.TextAlign = 2


lngNumdays is the number of days for the current month.

lngDayLength is the size of each day label based upon the number of days.

Each label is inside of a invisable box called Me.boxTimeline2 which is why
all of the sizes of the labes is based upon that box.

As you can see, i have the exact same settings for each label except for the
Left which is based upon all of the previous lables sizes.

Thanks again for all of your help!


"Marshall Barton" wrote:

> Then manually create 31 labels in the report's design. The
> report's Open event can then make some of them invisible
> depending on the month. For example,
>
> Select Case Month(datevalue)
> Case 4, 6, 9,11
> Me("lbl31").Visible = False
> Case 2
> Me("lbl31").Visible = False
> Me("lbl30").Visible = False
> If Day(DateSerial(Year(datevalue), 2, 29)) <> 29 _
> Then Me("lbl29").Visible = False
> End If
> End Select
>
>
> drewdavis1 wrote:
> >What i'm trying to do is create a loop that will create a label for each day
> >of the month (1,2,3,etc) based upon the number of days in a month and display
> >them in a line at the top of the report.
> >
> >"Cyberwolf" wrote:
> >> Good point Marshall, I just assumed it was something he wanted to do based on
> >> an in put on a form someplace. i.e. how many children the person has and
> >> would create text box for that number.
> >>
> >> "Marshall Barton" wrote:
> >>
> >> > drewdavis1 wrote:
> >> > >Could you please give me a code sample, including the code to create the
> >> > >textbox/label? I am pretty new at VB and this would really help.
> >> > >
> >> > >>
> >> > >> "drewdavis1" wrote:
> >> > >> > I was wondering how I would go about creating a loop that would generate a
> >> > >> > specified number of TextBoxes or Labels in a report.
> >> >
> >> >
> >> > I have to say that if you are new to VB/VBA, then you are
> >> > getting off on the wrong foot about using controls.
> >> >
> >> > The only time you would want to write a VBA procedure to
> >> > create controls is if you are writing a **design** time
> >> > wizard for yourself.
> >> >
> >> > For a **runtime** operation, you should (manually or using
> >> > code) precreate all possible needed controls at **design**
> >> > time, then make them visible as needed at run time.
> >> >
> >> > If you'll explain more about **what** you're trying to
> >> > accomplish (instead of the way you've thought to do it),
> >> > then maybe someone will be able to provide a better idea.
> >> >
> >> > --
> >> > Marsh
> >> > MVP [MS Access]
> >> >

>
> --
> Marsh
> MVP [MS Access]
>

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      21st Jun 2005
drewdavis1 wrote:
>Thanks for your input, but that not exactly what i'm looking for. I'm sorry,
>i guess i wan't clear enough. I'm working on a Gantt style calendar to
>display a schedule one month at a time. I have everything working but the
>last thing I want to do is to make they days of the month dynamic based on
>the number of days in the month. The labels for the days of the month width
>vaires based upon how many days since the entire width of all the days is a
>fixed width. Below is a copy and paste of the code that i have written that
>works, but is cumbersome to write and i was wondering if i could use a loop
>instead:
>
>Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
>Integer)
>Dim lngNumDays As Long
>Dim lngDayLength As Long
>lngNumDays = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
>lngDayLength = Me.boxTimeLine2.Width / lngNumDays
>
>Me.Date1.Height = Me.boxTimeLine2.Height
>Me.Date1.Width = lngDayLength
>Me.Date1.Top = Me.boxTimeLine2.Top
>Me.Date1.Left = Me.boxTimeLine2.Left
>Me.Date1.BorderStyle = 1
>Me.Date1.TextAlign = 2
>
>Me.Date2.Height = Me.boxTimeLine2.Height
>Me.Date2.Width = lngDayLength
>Me.Date2.Top = Me.boxTimeLine2.Top
>Me.Date2.Left = Me.boxTimeLine2.Left + Me.Date1.Width
>Me.Date2.BorderStyle = 1
>Me.Date2.TextAlign = 2
>
>Me.Date3.Height = Me.boxTimeLine2.Height
>Me.Date3.Width = lngDayLength
>Me.Date3.Top = Me.boxTimeLine2.Top
>Me.Date3.Left = Me.boxTimeLine2.Left + Me.Date1.Width + Me.Date2.Width
>Me.Date3.BorderStyle = 1
>Me.Date3.TextAlign = 2
>
>
>lngNumdays is the number of days for the current month.
>
>lngDayLength is the size of each day label based upon the number of days.
>
>Each label is inside of a invisable box called Me.boxTimeline2 which is why
>all of the sizes of the labes is based upon that box.
>
>As you can see, i have the exact same settings for each label except for the
>Left which is based upon all of the previous lables sizes.



Here's a shot at it:

Private Sub PageHeaderSection_Format(Cancel As Integer,
FormatCount As Integer)
Dim lngNumDays As Long
Dim lngDayLength As Long
Dim lngLeft As Long
Dim k As Integer

lngNumDays = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
lngDayLength = Me.boxTimeLine2.Width / lngNumDays
lngLeft = Me.boxTimeLine2.Left

For k = 1 To lngNumDays
With Me("Date" & k)
.Height = Me.boxTimeLine2.Height
.Width = lngDayLength
.Top = Me.boxTimeLine2.Top
.Left = lngLeft + (k - 1) * lngDayLength
.BorderStyle = 1
.TextAlign = 2
End Wih
Next k

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
=?Utf-8?B?ZHJld2RhdmlzMQ==?=
Guest
Posts: n/a
 
      22nd Jun 2005
It worked great! Thank you so much!!!

"Marshall Barton" wrote:

> drewdavis1 wrote:
> >Thanks for your input, but that not exactly what i'm looking for. I'm sorry,
> >i guess i wan't clear enough. I'm working on a Gantt style calendar to
> >display a schedule one month at a time. I have everything working but the
> >last thing I want to do is to make they days of the month dynamic based on
> >the number of days in the month. The labels for the days of the month width
> >vaires based upon how many days since the entire width of all the days is a
> >fixed width. Below is a copy and paste of the code that i have written that
> >works, but is cumbersome to write and i was wondering if i could use a loop
> >instead:
> >
> >Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
> >Integer)
> >Dim lngNumDays As Long
> >Dim lngDayLength As Long
> >lngNumDays = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
> >lngDayLength = Me.boxTimeLine2.Width / lngNumDays
> >
> >Me.Date1.Height = Me.boxTimeLine2.Height
> >Me.Date1.Width = lngDayLength
> >Me.Date1.Top = Me.boxTimeLine2.Top
> >Me.Date1.Left = Me.boxTimeLine2.Left
> >Me.Date1.BorderStyle = 1
> >Me.Date1.TextAlign = 2
> >
> >Me.Date2.Height = Me.boxTimeLine2.Height
> >Me.Date2.Width = lngDayLength
> >Me.Date2.Top = Me.boxTimeLine2.Top
> >Me.Date2.Left = Me.boxTimeLine2.Left + Me.Date1.Width
> >Me.Date2.BorderStyle = 1
> >Me.Date2.TextAlign = 2
> >
> >Me.Date3.Height = Me.boxTimeLine2.Height
> >Me.Date3.Width = lngDayLength
> >Me.Date3.Top = Me.boxTimeLine2.Top
> >Me.Date3.Left = Me.boxTimeLine2.Left + Me.Date1.Width + Me.Date2.Width
> >Me.Date3.BorderStyle = 1
> >Me.Date3.TextAlign = 2
> >
> >
> >lngNumdays is the number of days for the current month.
> >
> >lngDayLength is the size of each day label based upon the number of days.
> >
> >Each label is inside of a invisable box called Me.boxTimeline2 which is why
> >all of the sizes of the labes is based upon that box.
> >
> >As you can see, i have the exact same settings for each label except for the
> >Left which is based upon all of the previous lables sizes.

>
>
> Here's a shot at it:
>
> Private Sub PageHeaderSection_Format(Cancel As Integer,
> FormatCount As Integer)
> Dim lngNumDays As Long
> Dim lngDayLength As Long
> Dim lngLeft As Long
> Dim k As Integer
>
> lngNumDays = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
> lngDayLength = Me.boxTimeLine2.Width / lngNumDays
> lngLeft = Me.boxTimeLine2.Left
>
> For k = 1 To lngNumDays
> With Me("Date" & k)
> .Height = Me.boxTimeLine2.Height
> .Width = lngDayLength
> .Top = Me.boxTimeLine2.Top
> .Left = lngLeft + (k - 1) * lngDayLength
> .BorderStyle = 1
> .TextAlign = 2
> End Wih
> Next k
>
> --
> Marsh
> MVP [MS Access]
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I am new to VBE. How can I create a for loop without typing it intothe code. dave186@gmail.com Microsoft Excel Programming 3 14th Mar 2008 04:01 PM
Help with Code - Create Textbox gatarossi@ig.com.br Microsoft Access 2 8th Jul 2007 05:39 PM
How to create textbox control via code? newst Microsoft Access Form Coding 1 21st Feb 2007 11:28 PM
How to create a bar code label in MS Access =?Utf-8?B?QXJub2xk?= Microsoft Access 5 7th Jul 2006 01:07 PM
Changing the BackColor of a label, box or textbox via code Alp Bekisoglu Microsoft Access Reports 3 30th May 2004 08:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 PM.