Minimizing Empty lines on a report

Adamantium42

New member
Local time
Today, 09:29
Joined
Jul 30, 2013
Messages
4
Hello.

I am looking for a bit of guidance.. I am trying to learn VBA code with Access and despite having a nice big book there is something I am struggling with.

The overall goal is to hide a whole line of a report using "canshrink" on a series of boxes, some of which are numbers and some that aren't. Some will be blank when the data is loaded into the form and I want these to make the rest of the form adjust.

Code:
Private Sub Form_Load()

If Me.Label33.Value = "<1" Then
Me.Label34.Caption = "Nothing."
End If

End Sub

I was just wondering if anyone can point out what's wrong with that code above? It's the first piece I've tried writing and I'm finding it hard to find anywhere that lists specific rules when writing VBA. I am under the impression that I don't need an "else" or anything like that.

I also attached a .zip file with the image inside of it.

Many thanks.
 

Attachments

Not enough information provided but I would suggest that rather than having this code on the Load event; try it on the
Code:
 Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
event.

ALSO the Property for Me.Label33.Value should be me.Label33.caption

Labels don't have Values.
 
As far as I know (and is not too far :) ) a label hasn't a property .Value
So, by follow this line, can't be compared with a value (<1 in your case).

Me.Label34.Caption = "Nothing."
If you wish that that label to display the word "Nothing" then this is the right way.
But, if you wish that label to be empty then I advice you to use this:
Me.Label34.Caption = " "

 
Not enough information provided but I would suggest that rather than having this code on the Load event; try it on the
Code:
 Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
event.

ALSO the Property for Me.Label33.Value should be me.Label33.caption

Labels don't have Values.

Thankyou tedmartin.

I actually just called a text box label33 - it does display a count from a table. I named it earlier one when I couldn't really tell the difference so i renamed that now.

I was wondering if you could explain -
Code:
 Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
- to me. I have Google'd it and found no real explanation to what it does.

My code is now:

Code:
Private Sub Form_Load()
If Me.txt36.Value = "<1" Then
Me.Label33.Visible = False
End If
End Sub

If I manually change visible to false in design mode it all works fine in theory so all I really need is if a text box, that imports data from a table, has no value loaded in it, it turns that label invisible and therefore shrinks the form in print preview mode.

If you wish that that label to display the word "Nothing" then this is the right way.
But, if you wish that label to be empty then I advice you to use this:
Me.Label34.Caption = " "

Thanks Mihail. I did actually want it to be empty however I put nothing in to make the code simpler for myself.

Thanks so far!
 

Users who are viewing this thread

Back
Top Bottom