By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

Conditional command Button?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.