Disable Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I have a button on my main form to run a query. This query should only be
run once per record ever. I tried disabling the button after it is clicked,
but then the botton is disabled on every record, not just the one I'm
viewing. And, when I reopen the application the button is no longer disabled.
Is there a way around this with VB?

My goal is that when you view a record in my form, if the button is grayed
out, you know that the query has been run on that particular record already.
Or an alternative would be to insert some sort of error to let you know the
query has already been run on that rcord...

Many thanks in advance :-)
 
You could add a yes/no field to the table, and set it when you run your
query. Then, you can set the button's enabled property based on the value
of the yes/no field.
 
The easiest way of doing as you suggest would be to have an additional
field in your table, one that is either true or false. Lets call that
field QueryRunYet. Then on the form Current event, add this piece of code:

me.cmdRunQuery.enabled = not QueryRunYet

This will then enable or disable the command button depending upon whether
the query has been run or not (assuming you name your command button
cmdRunQuery).

You will also have to update this field after you run your query.

Hope that helps

John Webb
 
debraj007 said:
Hi! I have a button on my main form to run a query. This query should
only be run once per record ever. I tried disabling the button after
it is clicked, but then the botton is disabled on every record, not
just the one I'm viewing. And, when I reopen the application the
button is no longer disabled. Is there a way around this with VB?

My goal is that when you view a record in my form, if the button is
grayed out, you know that the query has been run on that particular
record already. Or an alternative would be to insert some sort of
error to let you know the query has already been run on that rcord...

Many thanks in advance :-)

There has to be some way to tell that the query has been run for any
given record. That could be a boolean (Yes/No) field in the record that
is initially False but is set to True when the query is run; or if
running the query changes data in some table, it may be possible to
examine that data and determine whether the query has been run for this
record.

So long as there is *some* way to tell, then you can use code in the
form's Current event to check it and enable or disable your command
button accordingly.
 
Back
Top