public procedure

H

harleyken

I would like to show a label (no record found) if the search shows no results..
here is the code:

Private Sub Text84_GotFocus()
Me.CheckRecordCount
End Sub
_____________________________________
Public Sub CheckRecordCount()
If Me.Recordset.RecordCount > 0 Then
Me.no_record_label
Else
Me.show_record_label
End If
End Sub
____________________________________
Public Sub no_record_label()
Me.Label83.Visible = True
Me.Text9.SetFocus
End Sub
_____________________________________
Public Sub show_record_label()
Me.Label83.Visible = False
End Sub
 
M

Marshall Barton

harleyken said:
I would like to show a label (no record found) if the search shows no results..
here is the code:

Private Sub Text84_GotFocus()
Me.CheckRecordCount
End Sub
_____________________________________
Public Sub CheckRecordCount()
If Me.Recordset.RecordCount > 0 Then
Me.no_record_label
Else
Me.show_record_label
End If
End Sub
____________________________________
Public Sub no_record_label()
Me.Label83.Visible = True
Me.Text9.SetFocus
End Sub
_____________________________________
Public Sub show_record_label()
Me.Label83.Visible = False
End Sub


It seems like you should check for RecordCount = 0 instead
of > 0
 
D

Dale Fye

My first thought is that you need to start using a naming convention. How
the hell do you know what Text84 is or label83? You really should take the
time to change the names associated with the controls on your forms. There
are several good naming conventions for Access controls. On of them is:

http://www.mvps.org/access/general/gen0012.htm

Secondly, unless you are going to reuse the subroutines "no_record_Label"
and "show_record_label" from multiple places in your code, it makes more
sense, and is far more readable to just put those couple of lines of text in
subroutine CheckRecordCount.

Third, I would use the RecordsetClone property rather than Recordset. I've
had instances where the Recordset.RecordCount did not return the total number
of records in recordset. And, as Marshall mentioned the check should look
like:

IF me.recordsetclone.RecordCount = 0 then
me.no_record_label
else
me.show_record_label
end if

Finally, and this is just personal preference, I would stop using the syntax
me.no_record_label to call a subroutine. Given that you are not using a
standard naming convention (see point #1), when I look at your code, I
initially have no idea what the object me.no_record_label is. My first
thought is to look for a control on your form with that name. If you want to
call a subroutine use the syntax:

Call no_record_label
 
H

harleyken

well.. being a completely self taught student of access..
Start using a naming convention.. I know what the text and labels are
because i have them in front of me - since I have several similar controls, I
found it was just as easy to let access name them.

I did put the extra lines of text in a subroutine. (it does make it easier
to read - another tid bit learned)

I had used "call" and it didn't seem to make a difference in the way it
ran..so I changed it back.

I had changed it to "=0" , when I saw it from Marshalls post- I realized
that was what I really wanted.

Unfortunately, even with my poor naming conventions and the math changed, it
still doesn't work. So - any idea where it went wrong [the logic - not the
conventions :) ]

My profession is far removed from programming - just trying to take
notebooks and paper logs and turn them into something efficient..
 
M

Marshall Barton

harleyken said:
I had changed it to "=0" , when I saw it from Marshalls post- I realized
that was what I really wanted.


I agree with Dale that you are probably(?) exercising
obscurity by creating all those procedures. I would code it
this way:

Private Sub Text84_GotFocus()
Me.Label83.Visible = (Me.Recordset.RecordCount = 0)
End Sub

I even tested it to make sure it works.

Don't forget that nothing will happen until you click on or
tab onto Text84

I also agree with Dale about using meaningful names for
fields and controls. You may think it's all clear to you
now, but take it from someone that has been programming
for over 45 years, it won't be so clear when you decide to
make a change a year or so from now.
 
H

harleyken

Marsh;
thanks! your solution is much simpler, I appriciate your time and effort to
help those of us without the knowledge/experience.
ps: I'll work on the naming conventions!
 

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