syntax cleanup

  • Thread starter Thread starter mark r
  • Start date Start date
M

mark r

please help me clean up this syntax


for each record in
![TBLNAME]
if
![TBLNAME]![datefield] =
("format(forms!formname!datefilter, '\#mm\/dd\/yyyy\#'")
then
![TBLNAME]![flagfield] = true
end if
Next Record
 
mark r said:
please help me clean up this syntax


for each record in
![TBLNAME]
if
![TBLNAME]![datefield] =
("format(forms!formname!datefilter, '\#mm\/dd\/yyyy\#'")
then
![TBLNAME]![flagfield] = true
end if
Next Record


I could probably contrive a database design and code declarations such
that that would be valid syntax, but it probably isn't what you are
really trying to do. If your purpose is update those records in table
"TBLNAME" that have the field "datefield" equal to the date value in
control "datefilter" on form "formname", setting the field "flagfield"
in these records to True, then it is much easier to do with an update
query. For example,

CurrentDb.Execute _
"UPDATE TBLNAME SET flagfield = True " & _
"WHERE datefield=" & _
Format(Forms!formname!datefilter, "\#mm\/dd\/yyyy\#"),
dbFailOnError

would do it. You need a reference to the DAO object library, to pick up
the defined constanr dbFailOnError.
 
Then I take it I have no syntax errors? this will work
fine in a command button as is ??!! It doesn't seem to
work....I get expression erros and others
-----Original Message-----
What is it you want to clean up?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



please help me clean up this syntax


for each record in
![TBLNAME]
if
![TBLNAME]![datefield] =
("format(forms!formname!datefilter, '\#mm\/dd\/yyyy\#'")
then
![TBLNAME]![flagfield] = true
end if
Next Record



.
 
I am too novice to understand:
You need a reference to the DAO object library, to pick up
the defined constanr dbFailOnError.

what does this mean.....how do I do "a reference"


please
 
What is it you're trying to do? What are record and table declared as?
Where are you trying to run this code?

You haven't given nearly enough information...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



mark r said:
Then I take it I have no syntax errors? this will work
fine in a command button as is ??!! It doesn't seem to
work....I get expression erros and others
-----Original Message-----
What is it you want to clean up?


please help me clean up this syntax


for each record in
![TBLNAME]
if
![TBLNAME]![datefield] =
("format(forms!formname!datefilter, '\#mm\/dd\/yyyy\#'")
then
![TBLNAME]![flagfield] = true
end if
Next Record



.
 
I am getting a Compile error:.... expected end of statement


-----Original Message-----
please help me clean up this syntax


for each record in
![TBLNAME]
if
![TBLNAME]![datefield] =
("format(forms!formname!datefilter, '\#mm\/dd\/yyyy\#'")
then
![TBLNAME]![flagfield] = true
end if
Next Record


I could probably contrive a database design and code declarations such
that that would be valid syntax, but it probably isn't what you are
really trying to do. If your purpose is update those records in table
"TBLNAME" that have the field "datefield" equal to the date value in
control "datefilter" on form "formname", setting the field "flagfield"
in these records to True, then it is much easier to do with an update
query. For example,

CurrentDb.Execute _
"UPDATE TBLNAME SET flagfield = True " & _
"WHERE datefield=" & _
Format(Forms!formname!

datefilter, "\#mm\/dd\/yyyy\#"),
 
oh, is that all to be on one line from CurrentDb.Execute
straight through to dbFailOnError
that seemed to work


I did not pu tit any "reference" yet it worked, is that a
pproblem? what's a "reference"?
 
With any code module open, Go to:
Tools-> References
and you will see all the external libraries that are referenced in order to make
your code work!
 
mark r said:
oh, is that all to be on one line from CurrentDb.Execute
straight through to dbFailOnError
that seemed to work

Oops, I see I left off one of the continuation characters -- the
underscores ("_")at the ends of the lines. Yes, if you put it all on
one line, it ought to work.
I did not pu tit any "reference" yet it worked, is that a
pproblem? what's a "reference"?

No, it's not a problem; it probably means your database already has a
reference set to the DAO Object Library. A reference, in this sense, is
a stored path to an external library that provides code routines or
object definitions that may be used in your application.
 
thanks, your comments are very helpful.
If I do at some other point in the future have to "make a
reference", how does one do it?

like a DIM stmt at the beginning of a PRIVATE SUB?
what is the syntax?
 
mark r said:
thanks, your comments are very helpful.
If I do at some other point in the future have to "make a
reference", how does one do it?

like a DIM stmt at the beginning of a PRIVATE SUB?
what is the syntax?

In the VB Editor, click the menu items Tools -> References... to open
the References dialog. That will show you the available libraries, with
check marks by the ones you currently have set as references in your
application. Setting a new reference from among the available ones is
as simple as putting a check mark in the box next to it.
 
Back
Top