PC Review


Reply
Thread Tools Rate Thread

Form Referencing

 
 
=?Utf-8?B?Y2hlcm1hbg==?=
Guest
Posts: n/a
 
      16th Mar 2006
I have a public procedure where I cycle through my labels and pass the
caption to a spreadsheet.

The thing I'm having trouble with is that the label names on the form I'm
referencing are "lblField1", "lblField2", etc, and I want to cycle through
them with a For Next loop.

I’m using [Forms]![frmUserCount]![lblField1], as in:

".Cells(I, K).Value = [Forms]![frmUserCount]![lblField1].Caption"

Instead of having a line like this for every label I want to reference (and
there are 46 of them), I want to use a For Next loop. Can anyone help with
this?

Thanks in advance,
Clint
 
Reply With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      17th Mar 2006
2 approaches:
- I is incremented in both so that you are filling a column with your labels
and aren't constantly overwriting the same cell.
- I assume this is within a "With..EndWith" block because of your
..Cells(I,K) usage.

' Method1: Cycle through all controls and grab the captions of all labels.
Dim ctl as Control
For each ctl in [Forms]![frmUserCount].Controls
If ctl.ControlType = acLabel Then
' (acLabel =100 so "If ctl.ControlType = 100 Then" could also be
used)
.Cells(I, K).Value = ctl.Caption
I = I + 1
End If
Next ctl


' Method2: Get the captions of labels with specific names (lblField1 through
lblField46)
' Note: as long as labels with these names exist, this method also
guarantees the order in which
' captions will be retrieved, which Method 1 might not.
Dim c as Integer
For c = 1 to 46
.Cells(I, K).Value = [Forms]![frmUserCount].Controls("lblField" &
c).Caption
I = I + 1
Next c

HTH
--
George Nicholson

Remove 'Junk' from return address.

"cherman" <(E-Mail Removed)> wrote in message
news:5E140545-1B02-4F01-8003-(E-Mail Removed)...
>I have a public procedure where I cycle through my labels and pass the
> caption to a spreadsheet.
>
> The thing I'm having trouble with is that the label names on the form I'm
> referencing are "lblField1", "lblField2", etc, and I want to cycle through
> them with a For Next loop.
>
> I'm using [Forms]![frmUserCount]![lblField1], as in:
>
> ".Cells(I, K).Value = [Forms]![frmUserCount]![lblField1].Caption"
>
> Instead of having a line like this for every label I want to reference
> (and
> there are 46 of them), I want to use a For Next loop. Can anyone help with
> this?
>
> Thanks in advance,
> Clint



 
Reply With Quote
 
=?Utf-8?B?Y2hlcm1hbg==?=
Guest
Posts: n/a
 
      17th Mar 2006
Your 2nd example whas EXACTLY what I was looking for. I knew there was an
easier way to do this! Thank you.

"George Nicholson" wrote:

> 2 approaches:
> - I is incremented in both so that you are filling a column with your labels
> and aren't constantly overwriting the same cell.
> - I assume this is within a "With..EndWith" block because of your
> ..Cells(I,K) usage.
>
> ' Method1: Cycle through all controls and grab the captions of all labels.
> Dim ctl as Control
> For each ctl in [Forms]![frmUserCount].Controls
> If ctl.ControlType = acLabel Then
> ' (acLabel =100 so "If ctl.ControlType = 100 Then" could also be
> used)
> .Cells(I, K).Value = ctl.Caption
> I = I + 1
> End If
> Next ctl
>
>
> ' Method2: Get the captions of labels with specific names (lblField1 through
> lblField46)
> ' Note: as long as labels with these names exist, this method also
> guarantees the order in which
> ' captions will be retrieved, which Method 1 might not.
> Dim c as Integer
> For c = 1 to 46
> .Cells(I, K).Value = [Forms]![frmUserCount].Controls("lblField" &
> c).Caption
> I = I + 1
> Next c
>
> HTH
> --
> George Nicholson
>
> Remove 'Junk' from return address.
>
> "cherman" <(E-Mail Removed)> wrote in message
> news:5E140545-1B02-4F01-8003-(E-Mail Removed)...
> >I have a public procedure where I cycle through my labels and pass the
> > caption to a spreadsheet.
> >
> > The thing I'm having trouble with is that the label names on the form I'm
> > referencing are "lblField1", "lblField2", etc, and I want to cycle through
> > them with a For Next loop.
> >
> > I'm using [Forms]![frmUserCount]![lblField1], as in:
> >
> > ".Cells(I, K).Value = [Forms]![frmUserCount]![lblField1].Caption"
> >
> > Instead of having a line like this for every label I want to reference
> > (and
> > there are 46 of them), I want to use a For Next loop. Can anyone help with
> > this?
> >
> > Thanks in advance,
> > Clint

>
>
>

 
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
Re: Referencing Parent Form from Sub Form & SQL Union Qry Question Allen Browne Microsoft Access Form Coding 0 6th Dec 2006 03:02 AM
Referencing Sub-form field from the main form. ------H E L P lalexander Microsoft Access Forms 4 17th May 2006 09:26 PM
Referencing Sub-form field from the main form. ------H E L P lalexander Microsoft Access External Data 4 17th May 2006 09:26 PM
Referencing Sub-form field from the main form. ------H E L P lalexander Microsoft Access Queries 2 17th May 2006 09:18 PM
Record source of form referencing acontrol on another OPEN form Spidey3721 Microsoft Access 1 17th Dec 2003 11:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 PM.