Solved

Change Caption of Access Button Based on Form Data

Posted on 2014-07-22
7
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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 …

734 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