Auto Adjust Height using VBA (1 Viewer)

trdummy

New member
Local time
Today, 17:12
Joined
Mar 5, 2013
Messages
3
Good Morning,

I currently have a report that pulls information from queries together. After creating the report to match the appearance of a PDF form we used back in the day, I discovered the report footer would have to be sized manually each time this report is created as the amount of records changes each time. Each page holds 34 records. I am about to pass information to someone taking over for me and it would be nice to auto height the report footer. I wrote the code at the bottom to "auto" height the report footer. I will update the code at the bottom as changes are made.
1. I keep getting this error; "Run-time error '2424:
The expression you entered has a field, control, or property name that Microsoft Access can't find." When I press debug, the 2nd line is high-lighted. Any help would be appreciated. CounterDuh is the count statement (textbox) for the records on the report as I have yet to be able to find a function that counts records on each page. NFE is the label in the Report footer and OMGFooter is the name of the report footer.

*** Edits
I Changed the beginning to see if it would change anything regarding errors.

Sub Report_Open()
Dim TotRemains As Integer
TotRemains = CounterDuh - (([Pages] - 1) * 34)
... etc. (Same As Above)
Now I get this error;
"The expression On Open you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro."

I'll be honest I have not done coding in almost 10 years ago. C++ I remember being awesome and I also remember every other coding language I could read fairly easy because of C++. I guess It's just been too long. I'm on a tangent. Ugh!

I apologize as I am trying to do many things at once without fixing problems but I think I am back at the original issue.

I changed the top again.

Sub Report_Open()
Dim TotalLastPage As Integer
TotalLastPage = CounterDuh
'Loop created to get remainder of records on last page
Do While TotalLastPage > 34
TotalLastPage -34
Loop
'IfThenElse Statement used to assign height to both Report footer and label.
If TotalLastPage = 34 Then
Me!NFE.Height = 0
Me!OMGFooter.Height = 0
ElseIf TotalLastPage = 33 Then
... etc.

Now I recieve another error...

Compile error:
Expected Sub, Function, or Property

Code:
Sub Report_Open()
        Dim TotalLastPage As Integer
        TotalLastPage = CounterDuh
        'Loop created to get remainder of records on last page
        Do While TotalLastPage > 34
        TotalLastPage -34
        Loop
        'IfThenElse Statement used to assign height to both Report footer and label.
        If TotalLastPage = 34 Then
            Me!NFE.Height = 0
            Me!OMGFooter.Height = 0
        ElseIf TotalLastPage = 33 Then
            Me!NFE.Height = 454
            Me!OMGFooter.Height = 454
        ElseIf TotalLastPage = 32 Then
            Me!NFE.Height = 688
            Me!OMGFooter.Height = 688
        ElseIf TotalLastPage = 31 Then
            Me!NFE.Height = 922
            Me!OMGFooter.Height = 922
        ElseIf TotalLastPage = 30 Then
            Me!NFE.Height = 1156
            Me!OMGFooter.Height = 1156
        ElseIf TotalLastPage = 29 Then
            Me!NFE.Height = 1390
            Me!OMGFooter.Height = 1390
        ElseIf TotalLastPage = 28 Then
            Me!NFE.Height = 1624
            Me!OMGFooter.Height = 1624
        ElseIf TotalLastPage = 27 Then
            Me!NFE.Height = 1858
            Me!OMGFooter.Height = 1858
        ElseIf TotalLastPage = 26 Then
            Me!NFE.Height = 2092
            Me!OMGFooter.Height = 2092
        ElseIf TotalLastPage = 25 Then
            Me!NFE.Height = 2326
            Me!OMGFooter.Height = 2326
        ElseIf TotalLastPage = 24 Then
            Me!NFE.Height = 2560
            Me!OMGFooter.Height = 2560
        ElseIf TotalLastPage = 23 Then
            Me!NFE.Height = 2794
            Me!OMGFooter.Height = 2794
        ElseIf TotalLastPage = 22 Then
            Me!NFE.Height = 3028
            Me!OMGFooter.Height = 3028
        ElseIf TotalLastPage = 21 Then
            Me!NFE.Height = 3262
            Me!OMGFooter.Height = 3262
        ElseIf TotalLastPage = 20 Then
            Me!NFE.Height = 3496
            Me!OMGFooter.Height = 3496
        ElseIf TotalLastPage = 19 Then
            Me!NFE.Height = 3730
            Me!OMGFooter.Height = 3730
        ElseIf TotalLastPage = 18 Then
            Me!NFE.Height = 3964
            Me!OMGFooter.Height = 3964
        ElseIf TotalLastPage = 17 Then
            Me!NFE.Height = 4198
            Me!OMGFooter.Height = 4198
        ElseIf TotalLastPage = 16 Then
            Me!NFE.Height = 4432
            Me!OMGFooter.Height = 4432
        ElseIf TotalLastPage = 15 Then
            Me!NFE.Height = 4666
            Me!OMGFooter.Height = 4666
        ElseIf TotalLastPage = 14 Then
            Me!NFE.Height = 4900
            Me!OMGFooter.Height = 4900
        ElseIf TotalLastPage = 13 Then
            Me!NFE.Height = 5134
            Me!OMGFooter.Height = 5134
        ElseIf TotalLastPage = 12 Then
            Me!NFE.Height = 5368
            Me!OMGFooter.Height = 5368
        ElseIf TotalLastPage = 11 Then
            Me!NFE.Height = 5602
            Me!OMGFooter.Height = 5602
        ElseIf TotalLastPage = 10 Then
            Me!NFE.Height = 5836
            Me!OMGFooter.Height = 5836
        ElseIf TotalLastPage = 9 Then
            Me!NFE.Height = 6070
            Me!OMGFooter.Height = 6070
        ElseIf TotalLastPage = 8 Then
            Me!NFE.Height = 6304
            Me!OMGFooter.Height = 6304
        ElseIf TotalLastPage = 7 Then
            Me!NFE.Height = 6538
            Me!OMGFooter.Height = 6538
        ElseIf TotalLastPage = 6 Then
            Me!NFE.Height = 6772
            Me!OMGFooter.Height = 6772
        ElseIf TotalLastPage = 5 Then
            Me!NFE.Height = 7006
            Me!OMGFooter.Height = 7006
        ElseIf TotalLastPage = 4 Then
            Me!NFE.Height = 7240
            Me!OMGFooter.Height = 7240
        ElseIf TotalLastPage = 3 Then
            Me!NFE.Height = 7474
            Me!OMGFooter.Height = 7474
        ElseIf TotalLastPage = 2 Then
            Me!NFE.Height = 7708
            Me!OMGFooter.Height = 7708
        ElseIf TotalLastPage = 1 Then
            Me!NFE.Height = 7942
            Me!OMGFooter.Height = 7942
        End If
End Sub
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 22:12
Joined
Feb 19, 2013
Messages
16,607
when you hover over each variable on the highlighted line it should show the variable value - if it can't find the variable it will show 'variable=empty'
 

trdummy

New member
Local time
Today, 17:12
Joined
Mar 5, 2013
Messages
3
When I hover over the highlighted line is states. "Cancel=0" line 6 is now highlighted.
 

Users who are viewing this thread

Top Bottom