Top Property

B

bw

I'm using code as follows:
If [NumLines] = 5 Then
[1stLine].Top = 0
End If

I'm getting a Compile error:
"Method or Data Member not found."

".Top =" is highlighted

I'm trying to dynamically move controls around the page. Is this the wrong
way to accomplish this?

Thanks for you help,
Bernie
 
B

Brendan Reynolds

My guess is that the report and the field to which it is bound are both
called '1stLine'. A field doesn't have a Top property, so you need to ensure
that VBA looks at the control, not at the field with the same name.
Me.Controls("1stLine").Top should work. For example, the following test code
worked for me.

Is that is the digit 1 (one) or the letter l (L) at the start of that name?
If it is the digit, that is not a good idea. A VBA procedure can not begin
with a digit, so if you create an event procedure for this control, VBA will
automatically prepend the letters 'Ctl', e.g. 'Private Sub
Ctl1stLine_AfterUpdate()'. This is a potential source of confusion.

Option Compare Database
Option Explicit

Private StartTop

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.CategoryID Mod 2 = 0 Then
Me.Controls("CategoryName").Top = StartTop + 50
Else
Me.Controls("CategoryName").Top = StartTop - 50
End If

End Sub

Private Sub Report_Open(Cancel As Integer)

StartTop = Me.Controls("CategoryName").Top

End Sub
 
B

bw

Thanks for your help, Brendan!

I changed the name of my controls as you suggested. I now have the
following procedure:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Controls("txtLine1").Top = Start Top
End Sub

After a lot of testing, I have come to the conclusion that StartTop does not
represent the same value that is on the text box property. For example,
txtLine1 has a Top property of 0. If I set StartTop with a value of 500,
the control moves down only about half the height of the control??

Initial "Top" Property for the following Controls:
txtLine1=0"
txtLine2=0.2"
txtLine3=0.4"
txtLine4=0.6"
txtLine5=0.8"

So in my procedure above, What would be the value of StartTop for each of
these initial values of Top for each control? And where is this information
documented in "Help" so that I can see it myself?

Thanks again,
Bernie



Brendan Reynolds said:
My guess is that the report and the field to which it is bound are both
called '1stLine'. A field doesn't have a Top property, so you need to
ensure that VBA looks at the control, not at the field with the same name.
Me.Controls("1stLine").Top should work. For example, the following test
code worked for me.

Is that is the digit 1 (one) or the letter l (L) at the start of that
name? If it is the digit, that is not a good idea. A VBA procedure can not
begin with a digit, so if you create an event procedure for this control,
VBA will automatically prepend the letters 'Ctl', e.g. 'Private Sub
Ctl1stLine_AfterUpdate()'. This is a potential source of confusion.

Option Compare Database
Option Explicit

Private StartTop

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.CategoryID Mod 2 = 0 Then
Me.Controls("CategoryName").Top = StartTop + 50
Else
Me.Controls("CategoryName").Top = StartTop - 50
End If

End Sub

Private Sub Report_Open(Cancel As Integer)

StartTop = Me.Controls("CategoryName").Top

End Sub

--
Brendan Reynolds (MVP)


bw said:
I'm using code as follows:
If [NumLines] = 5 Then
[1stLine].Top = 0
End If

I'm getting a Compile error:
"Method or Data Member not found."

".Top =" is highlighted

I'm trying to dynamically move controls around the page. Is this the
wrong way to accomplish this?

Thanks for you help,
Bernie
 
B

bw

TWIPS!
I found it Brendan. Now I'm sorry I wasted your time with this. Thanks
much. I now have it working as I was expecting.
Bernie


Brendan Reynolds said:
My guess is that the report and the field to which it is bound are both
called '1stLine'. A field doesn't have a Top property, so you need to
ensure that VBA looks at the control, not at the field with the same name.
Me.Controls("1stLine").Top should work. For example, the following test
code worked for me.

Is that is the digit 1 (one) or the letter l (L) at the start of that
name? If it is the digit, that is not a good idea. A VBA procedure can not
begin with a digit, so if you create an event procedure for this control,
VBA will automatically prepend the letters 'Ctl', e.g. 'Private Sub
Ctl1stLine_AfterUpdate()'. This is a potential source of confusion.

Option Compare Database
Option Explicit

Private StartTop

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.CategoryID Mod 2 = 0 Then
Me.Controls("CategoryName").Top = StartTop + 50
Else
Me.Controls("CategoryName").Top = StartTop - 50
End If

End Sub

Private Sub Report_Open(Cancel As Integer)

StartTop = Me.Controls("CategoryName").Top

End Sub

--
Brendan Reynolds (MVP)


bw said:
I'm using code as follows:
If [NumLines] = 5 Then
[1stLine].Top = 0
End If

I'm getting a Compile error:
"Method or Data Member not found."

".Top =" is highlighted

I'm trying to dynamically move controls around the page. Is this the
wrong way to accomplish this?

Thanks for you help,
Bernie
 

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