473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Conditional command Button?

I have a main form with a command button on it that when clicked,
opens a subform displaying records that relate to the main form.
I would like to disable the command button if the corresponding
subform does not contain a record.
I'm guessing this action would take place in the OnClick event of the
command button but I'm not sure what the VB code is for checking if a
record exists.
Any coding examples and suggestions would be very helpful.
Thanks...CM
Nov 13 '05 #1
2 3827
On 20 Jul 2004 11:30:49 -0700, co***@muskoka.com (Colin) wrote:
I have a main form with a command button on it that when clicked,
opens a subform displaying records that relate to the main form.
I would like to disable the command button if the corresponding
subform does not contain a record.
I'm guessing this action would take place in the OnClick event of the
command button but I'm not sure what the VB code is for checking if a
record exists.
Any coding examples and suggestions would be very helpful.
Thanks...CM


You might use the main forms Current event to check if the subform has
any records. (I'm assuming the the "subform" is actually a separate
form, not actually a subform control)

If the basis of the recordsource of the subform is a table and the
related field might be a productID then you could proceed something
like...

Private Sub Form_Current()
Me.cmdButton.Enabled = DCount("*", "tblProds", "ProdID=" _
& Me.ProdID) > 0
End Sub

To do better I would have to know a little more about your forms and
data structure.

- Jim
Nov 13 '05 #2
Thanks Jim, your example saved the day!

Cheers....CM
"Jim Allensworth" <ji****@datacentricsolutions.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
On 20 Jul 2004 11:30:49 -0700, co***@muskoka.com (Colin) wrote:
I have a main form with a command button on it that when clicked,
opens a subform displaying records that relate to the main form.
I would like to disable the command button if the corresponding
subform does not contain a record.
I'm guessing this action would take place in the OnClick event of the
command button but I'm not sure what the VB code is for checking if a
record exists.
Any coding examples and suggestions would be very helpful.
Thanks...CM


You might use the main forms Current event to check if the subform has
any records. (I'm assuming the the "subform" is actually a separate
form, not actually a subform control)

If the basis of the recordsource of the subform is a table and the
related field might be a productID then you could proceed something
like...

Private Sub Form_Current()
Me.cmdButton.Enabled = DCount("*", "tblProds", "ProdID=" _
& Me.ProdID) > 0
End Sub

To do better I would have to know a little more about your forms and
data structure.

- Jim

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: in | last post by:
In Visual Studio, is there a way of marking a statement as a "conditional run". Sort of like a breakpoint, but there, in the debugger, the statement will not execute. I'm thinking of code...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
8
by: Not Me | last post by:
Hey, In order to customise rows on my gridview control, I've some code in the RowDataBound event, that works on each row, altering it's attributes.. for example I have: If...
0
by: GGerard | last post by:
Hello With MSAccess 2000, I have created a program with forms and applied some Conditional Formatting on some of the text box.
6
by: patrick j | last post by:
Hi I've been testing out the "Conditional Comment" for IE. This is because for my web-site I want to have two style sheets, one for IE 6 and one for other browsers. Thus I hope to have my...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
6
by: maxwell | last post by:
I'm trying to use the gpp utility (Gnu points to http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in Python, and I'm running into a problem: the same '#' character introduces...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.