Enable/Disable buttons ...

  • Thread starter Thread starter Li
  • Start date Start date
L

Li

I have a need to Enable/Disable buttons on a form
based on a query, what is the syntax to write
a query in form load and then
enable or disable button?

Something like
select count(*) into noofrecs from tablename where
type='X'
if noofrecs > 0 then
btn.Enable = YES
endif


Thank you,
-Li
 
Li,

You would use the DCOUNT function to return the number of
records based on a condtion, Query or Table. See help
for more details.

So for your example..

NumOfRecords = DCount("*", "TableName","Type=" & chr(34)
& "X" & chr(34))

if NumOfRecords > 0 then
btn.Enable = TRUE 'Note Use True/False for enabling
end if

Jeff
 
Jeff,

Thanks for the reply!
I implemented this on Form Load, I get the error -

"you cancelled previous operation"

and it points me to statement

NumOfRecords = DCount("*", "TableName","Type=" & chr(34)
& "X" & chr(34))

in my form load routine.

What I may be doing wrong?

Thank you,
-Li
 
Li,

This code I used as an example, did u put in your Table
Name ? Is their a field called "Type" in your Table ?

If still the error, copy & paste the acual code u are
using or if u want to Email me the database I can take a
look at it.

Jeff
(e-mail address removed)
 
Jeff,

When I use the following statement
NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] )

it works however, if I change it to the following
I get the error "You canceled previous operation"

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE=O")

Why I can't use multiple column names in my select here?

Thank you,
-Li
 
Li,

Try this...

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE= " & chr(34) & "O" & chr(34))


Jeff


-----Original Message-----
Jeff,

When I use the following statement
NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] )

it works however, if I change it to the following
I get the error "You canceled previous operation"

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE=O")

Why I can't use multiple column names in my select here?

Thank you,
-Li
-----Original Message-----
Li,

This code I used as an example, did u put in your Table
Name ? Is their a field called "Type" in your Table ?

If still the error, copy & paste the acual code u are
using or if u want to Email me the database I can take a
look at it.

Jeff
(e-mail address removed)


.
.
 
Jeff,

This worked!!!
I am stumped as to why it doesn't work w/0 chr(34)?

What is the value of chr(34)? I am getting double-quotes.
Is that the value you expect?

Thanks much,
-Li
-----Original Message-----
Li,

Try this...

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE= " & chr(34) & "O" & chr(34))


Jeff


-----Original Message-----
Jeff,

When I use the following statement
NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] )

it works however, if I change it to the following
I get the error "You canceled previous operation"

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE=O")

Why I can't use multiple column names in my select here?

Thank you,
-Li
-----Original Message-----
Li,

This code I used as an example, did u put in your Table
Name ? Is their a field called "Type" in your Table ?

If still the error, copy & paste the acual code u are
using or if u want to Email me the database I can take a
look at it.

Jeff
(e-mail address removed)


-----Original Message-----
Jeff,

Thanks for the reply!
I implemented this on Form Load, I get the error -

"you cancelled previous operation"

and it points me to statement

NumOfRecords = DCount("*", "TableName","Type=" & chr (34)
& "X" & chr(34))

in my form load routine.

What I may be doing wrong?

Thank you,
-Li


-----Original Message-----
Li,

You would use the DCOUNT function to return the number
of
records based on a condtion, Query or Table. See help
for more details.

So for your example..

NumOfRecords = DCount("*", "TableName","Type=" & chr
(34)
& "X" & chr(34))

if NumOfRecords > 0 then
btn.Enable = TRUE 'Note Use True/False for enabling
end if

Jeff

-----Original Message-----
I have a need to Enable/Disable buttons on a form
based on a query, what is the syntax to write
a query in form load and then
enable or disable button?

Something like
select count(*) into noofrecs from tablename where
type='X'
if noofrecs > 0 then
btn.Enable = YES
endif


Thank you,
-Li

.

.

.

.
.
.
 
Yes, Chr(34) is "

You need it because in regular SQL you would have
Type = 'O'

In Access SQL you need
Type = "O"

(you would think Microsoft would be consistant but of
course not)

So you need to surround the Text where clauses in ""
not ''

Jeff



-----Original Message-----
Jeff,

This worked!!!
I am stumped as to why it doesn't work w/0 chr(34)?

What is the value of chr(34)? I am getting double-quotes.
Is that the value you expect?

Thanks much,
-Li
-----Original Message-----
Li,

Try this...

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE= " & chr(34) & "O" & chr(34))


Jeff


-----Original Message-----
Jeff,

When I use the following statement
NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] )

it works however, if I change it to the following
I get the error "You canceled previous operation"

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE=O")

Why I can't use multiple column names in my select here?

Thank you,
-Li

-----Original Message-----
Li,

This code I used as an example, did u put in your Table
Name ? Is their a field called "Type" in your Table ?

If still the error, copy & paste the acual code u are
using or if u want to Email me the database I can
take
a
look at it.

Jeff
(e-mail address removed)


-----Original Message-----
Jeff,

Thanks for the reply!
I implemented this on Form Load, I get the error -

"you cancelled previous operation"

and it points me to statement

NumOfRecords = DCount("*", "TableName","Type=" & chr
(34)
& "X" & chr(34))

in my form load routine.

What I may be doing wrong?

Thank you,
-Li


-----Original Message-----
Li,

You would use the DCOUNT function to return the number
of
records based on a condtion, Query or Table. See help
for more details.

So for your example..

NumOfRecords = DCount("*", "TableName","Type=" & chr
(34)
& "X" & chr(34))

if NumOfRecords > 0 then
btn.Enable = TRUE 'Note Use True/False for
enabling
end if

Jeff

-----Original Message-----
I have a need to Enable/Disable buttons on a form
based on a query, what is the syntax to write
a query in form load and then
enable or disable button?

Something like
select count(*) into noofrecs from tablename where
type='X'
if noofrecs > 0 then
btn.Enable = YES
endif


Thank you,
-Li

.

.

.

.

.
.
.
 
Jeff,

Again I am getting the same error
"you canceled the previous operation' despite
my having chr(34), it worked one time and now
it isn't working again.

I am at total loss. Don't know what to do.

Any suggestions?

Thank you,
-Li
-----Original Message-----
Yes, Chr(34) is "

You need it because in regular SQL you would have
Type = 'O'

In Access SQL you need
Type = "O"

(you would think Microsoft would be consistant but of
course not)

So you need to surround the Text where clauses in ""
not ''

Jeff



-----Original Message-----
Jeff,

This worked!!!
I am stumped as to why it doesn't work w/0 chr(34)?

What is the value of chr(34)? I am getting double- quotes.
Is that the value you expect?

Thanks much,
-Li
-----Original Message-----
Li,

Try this...

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE= " & chr(34) & "O" & chr(34))


Jeff



-----Original Message-----
Jeff,

When I use the following statement
NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] )

it works however, if I change it to the following
I get the error "You canceled previous operation"

NumOfRecords = DCount("*", "DETAILS", "PROD=" & Me!
[PROD_NUM] & " and TYPE=O")

Why I can't use multiple column names in my select here?

Thank you,
-Li

-----Original Message-----
Li,

This code I used as an example, did u put in your Table
Name ? Is their a field called "Type" in your Table ?

If still the error, copy & paste the acual code u are
using or if u want to Email me the database I can take
a
look at it.

Jeff
(e-mail address removed)


-----Original Message-----
Jeff,

Thanks for the reply!
I implemented this on Form Load, I get the error -

"you cancelled previous operation"

and it points me to statement

NumOfRecords = DCount("*", "TableName","Type=" & chr
(34)
& "X" & chr(34))

in my form load routine.

What I may be doing wrong?

Thank you,
-Li


-----Original Message-----
Li,

You would use the DCOUNT function to return the
number
of
records based on a condtion, Query or Table. See
help
for more details.

So for your example..

NumOfRecords = DCount("*", "TableName","Type=" & chr
(34)
& "X" & chr(34))

if NumOfRecords > 0 then
btn.Enable = TRUE 'Note Use True/False for
enabling
end if

Jeff

-----Original Message-----
I have a need to Enable/Disable buttons on a form
based on a query, what is the syntax to write
a query in form load and then
enable or disable button?

Something like
select count(*) into noofrecs from tablename where
type='X'
if noofrecs > 0 then
btn.Enable = YES
endif


Thank you,
-Li

.

.

.

.

.

.
.
.
 
Back
Top