condition in a macro

D

Dan

I am prototyping an application involving a timer on a
form. On my form, I have an unbound control linked to a
table having only a counter field, updated every second by
the timer initiaiting a macro.
As this macro runs, after the counter is incremented, I
inserted a condition such that if the value of the control
= 4, then perform and update by executing the following 4
commands in the maco ( identified with ellipses in the
condition field).
In the macro, I entered into the condition field the
statement :

[forms]![Main Form]![list9] = 4

(this is the unbound control on the form tied to the
[counter]![count] field, in whuich there exists only 1
record containing the current count of seconds.)

If this statement is true, I want the macro to execute the
elllipses statements following the condition.

I hope you can see that what I am trying to do is "read"
the value of a unbound control on a form and apply a
numeric condition to it.
I have Access 97 running on NT 4.0. I have been getting
compile errors when using the statement [forms]![main
form]![list9].recordsource.
Can you tell me what statement I can use which will help me
in reading the unbound control.

Thanks

Dan
 
K

Ken Snell

I'm confused.

You state that you have tried to use this condition in a macro:
[forms]![Main Form]![list9] = 4

You then state that you're getting compile errors when using the statement
[forms]![main form]![list9].recordsource

Number one, yes, you'll get a compiler error with the second statement. Form
controls do not have a recordsource.

But the first expression that you posted should work fine. Is it not
working?
 
D

Dan

Yes. I am begin to conclude that I do not have Access 97
preferences (options) set correctly. I have encountered
lots of problems in data conversion, etc. For example, in
trying to do an update to a file, I need to convert a date
to a string so I can look up a corresponding "work day"
reference in another cusotme file I developed. I am unable
to get STR(
![date]) to convert the displayed date to
a string.

-----Original Message-----
I'm confused.

You state that you have tried to use this condition in a macro:
[forms]![Main Form]![list9] = 4

You then state that you're getting compile errors when using the statement
[forms]![main form]![list9].recordsource

Number one, yes, you'll get a compiler error with the second statement. Form
controls do not have a recordsource.

But the first expression that you posted should work fine. Is it not
working?

--
Ken Snell
<MS ACCESS MVP>

Dan said:
I am prototyping an application involving a timer on a
form. On my form, I have an unbound control linked to a
table having only a counter field, updated every second by
the timer initiaiting a macro.
As this macro runs, after the counter is incremented, I
inserted a condition such that if the value of the control
= 4, then perform and update by executing the following 4
commands in the maco ( identified with ellipses in the
condition field).
In the macro, I entered into the condition field the
statement :

[forms]![Main Form]![list9] = 4

(this is the unbound control on the form tied to the
[counter]![count] field, in whuich there exists only 1
record containing the current count of seconds.)

If this statement is true, I want the macro to execute the
elllipses statements following the condition.

I hope you can see that what I am trying to do is "read"
the value of a unbound control on a form and apply a
numeric condition to it.
I have Access 97 running on NT 4.0. I have been getting
compile errors when using the statement [forms]![main
form]![list9].recordsource.
Can you tell me what statement I can use which will help me
in reading the unbound control.

Thanks

Dan


.
 
K

Ken Snell

Dan said:
Yes. I am begin to conclude that I do not have Access 97
preferences (options) set correctly. I have encountered
lots of problems in data conversion, etc. For example, in
trying to do an update to a file, I need to convert a date
to a string so I can look up a corresponding "work day"
reference in another cusotme file I developed. I am unable
to get STR(
![date]) to convert the displayed date to
a string.


The Local Settings will play a big part in how conversions (such as date to
string) are done. If you want to control the exact format of such a date to
string conversion, use the Format function:

Format(
.[datefield], "dd/mm/yyyy")

Second, assuming that table in your STR example is a table name, the !
operator is not appropriate to separate a table name and a field name. Use
the . operator instead.

I think many of the issues that you're seeing may be caused by improper
syntax?

I still am not clear about what you're actually trying to use as the
expression in the Condition? with or without the recordsource ?
 
D

Dan

Ken,

I am trying to tie the macro condition -> [form]![main
form]![list9]= 6 to the read of the form
control, "list9", which is an unbound control on the main
form of my application.

I have activated an OnTimer event on my main form such
that every second it calls a macro to run. The macro has
a condition within it to test for the value of the control
and if it is equal to 6 to conditionally execute the rest
of the macro (as identified by the ellipses).

The OnTimer event is set to execute the macro ever 10
seconds (as a test case). One of the conditions in the
macro is to see when the counter (of each 10 second
occurence) has reached a count of 6 ( ie 1 minute has
passed).

What is not happening is when I read the control and it
says "5" and I have as the condition "[forms]![main form]!
[list9] = 6", I cannot get the condition to be activated.

Do you know what i may need to check or do you have an
alternative way for me to achieve the same result?

Thanks
Dan
-----Original Message-----
Yes. I am begin to conclude that I do not have Access 97
preferences (options) set correctly. I have encountered
lots of problems in data conversion, etc. For example, in
trying to do an update to a file, I need to convert a date
to a string so I can look up a corresponding "work day"
reference in another cusotme file I developed. I am unable
to get STR(
![date]) to convert the displayed date to
a string.


The Local Settings will play a big part in how conversions (such as date to
string) are done. If you want to control the exact format of such a date to
string conversion, use the Format function:

Format(
.[datefield], "dd/mm/yyyy")

Second, assuming that table in your STR example is a table name, the !
operator is not appropriate to separate a table name and a field name. Use
the . operator instead.

I think many of the issues that you're seeing may be caused by improper
syntax?

I still am not clear about what you're actually trying to use as the
expression in the Condition? with or without the recordsource ?

--
Ken Snell
<MS ACCESS MVP>


.
 
K

Ken Snell

Comments inline....


--
Ken Snell
<MS ACCESS MVP>

Dan said:
Ken,

I am trying to tie the macro condition -> [form]![main
form]![list9]= 6 to the read of the form
control, "list9", which is an unbound control on the main
form of my application.
OK.....


I have activated an OnTimer event on my main form such
that every second it calls a macro to run. The macro has
a condition within it to test for the value of the control
and if it is equal to 6 to conditionally execute the rest
of the macro (as identified by the ellipses).

OK - the timer event runs every second.
The OnTimer event is set to execute the macro ever 10
seconds (as a test case). One of the conditions in the
macro is to see when the counter (of each 10 second
occurence) has reached a count of 6 ( ie 1 minute has
passed).

Now I'm confused. In the previous paragraph, you said that the timer event
is running every second. Here you say it's running every 10 seconds. Which
is it?

And I don't see in your explanation any information regarding what is
causing the value in the list9 textbox to change?

What is not happening is when I read the control and it
says "5" and I have as the condition "[forms]![main form]!
[list9] = 6", I cannot get the condition to be activated.

But, if the value in the textbox is 5, then of course the condition "=6"
will fail, and the macro will not run. What is it that I'm not understanding
here?
Do you know what i may need to check or do you have an
alternative way for me to achieve the same result?

I am not fully understanding your setup. See my comments above. Until I can
understand it, I am reluctant to make any suggestions for alternate methods.

Let's start at the beginning. Tell me what you want to happen.....what is
the purpose of list9 textbox? what action(s) is to be done every second?
what action(s) is to be done every ten seconds?
Thanks
Dan
-----Original Message-----
Yes. I am begin to conclude that I do not have Access 97
preferences (options) set correctly. I have encountered
lots of problems in data conversion, etc. For example, in
trying to do an update to a file, I need to convert a date
to a string so I can look up a corresponding "work day"
reference in another cusotme file I developed. I am unable
to get STR(
![date]) to convert the displayed date to
a string.


The Local Settings will play a big part in how conversions (such as date to
string) are done. If you want to control the exact format of such a date to
string conversion, use the Format function:

Format(
.[datefield], "dd/mm/yyyy")

Second, assuming that table in your STR example is a table name, the !
operator is not appropriate to separate a table name and a field name. Use
the . operator instead.

I think many of the issues that you're seeing may be caused by improper
syntax?

I still am not clear about what you're actually trying to use as the
expression in the Condition? with or without the recordsource ?

--
Ken Snell
<MS ACCESS MVP>


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top