Solved

Change Caption of Access Button Based on Form Data

Posted on 2014-07-22
7
188 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

685 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