Solved

Change Caption of Access Button Based on Form Data

Posted on 2014-07-22
7
185 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Backup Your Microsoft Windows Server®

Backup 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.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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