Solved

Change Caption of Access Button Based on Form Data

Posted on 2014-07-22
7
186 Views
Last Modified: 2014-11-25
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.
0
Comment
Question by:shelbyinfotech
7 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 40212652
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
 

Author Comment

by:shelbyinfotech
ID: 40212695
This makes no sense:

txtRecordCount.Value: 2
txtRecordCount.Value:
txtRecordCount.Value:
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40212699
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40212785
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40213023
<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
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40213171
The Help topic says DCount returns a Variant, so I figured it might be a Null.  But maybe not.
0
 
LVL 20

Accepted Solution

by:
clarkscott earned 500 total points
ID: 40213457
How about  me.repaint  after you change the caption.

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

Scott C
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question