Change Caption of Access Button Based on Form Data

I have a textbox that is to be hidden on a form that uses the Count() function to count the rows in the form's recordset.

Using the On_Load event, I check to see if the value of the textbox is greater than one, attempting to change the caption of the button to either say "Add Record' or "Add Duplicate Record"

Like this:

If txtRecordCount.Value > 1 Then
Me.btnAdd.Caption = "Add Duplicate Record"
Else
Me.btnAdd.Caption = "Add Record"
End If

No error is produced, and the event is correct as I can debug through it with "txtRecordCount.Value > 1" however nothing happens.
shelbyinfotechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony BerenguelCommented:
Change your code to this and see what prints in the immediate window.  Then step over the line where you assign a value to the button's text.
if txtRecordCount.Value > 1 Then
    debug.print "txtRecordCount.Value: " & txtRecordCount.Value
    stop
    Me.btnAdd.Caption = "Add Duplicate Record"
Else
    debug.print "txtRecordCount.Value: " & txtRecordCount.Value
    stop
    Me.btnAdd.Caption = "Add Record"
End If

Open in new window

0
shelbyinfotechAuthor Commented:
This makes no sense:

txtRecordCount.Value: 2
txtRecordCount.Value:
txtRecordCount.Value:
0
Rey Obrero (Capricorn1)Commented:
try this

private sub form_load()

if dcount("*",me.recordsource) >1 then
Me.btnAdd.Caption = "Add Duplicate Record"
Else
Me.btnAdd.Caption = "Add Record"
End If

end sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Helen FeddemaCommented:
You might need to rerun the code on the Current event, as well as (or instead of) the Load event.  Also, it is a good idea to wrap the DCount expression in Nz().
0
Rey Obrero (Capricorn1)Commented:
<it is a good idea to wrap the DCount expression in Nz(). >

that is redundancy, dcount does not return a null value, it is 0 or a number value.
0
Helen FeddemaCommented:
The Help topic says DCount returns a Variant, so I figured it might be a Null.  But maybe not.
0
clarkscottCommented:
How about  me.repaint  after you change the caption.

Me.btnAdd.Caption = "Add Duplicate Record"
me.repaint

Scott C
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.