Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Running an Update query before closing a form

Geek News

Running an Update query before closing a form
randria 12/11/2008 8:58:01 AM
Hello everyone,

I have form ( record sourece table1)that has a control (ctr1) whose value I
need to update to a field in a different table ( table2). I have a command
button that I have to click everytime before closing the form to run an
update query so that the current value of ctr1 is copied to the field in
table2.
- It works fine when new records were posted. But when previous records were
changed or deleted, it gives an error message ( the db couldn't run the
update query and couldn t save all records because of various violations
.....) .
2 questions:
1-is it possible to remove the command button and programmatically run
the update query before closing ? I have not written an SQL in codes. I
tried to copy the SQL from SQL View but I get errors.

2- What should I do before running the update query in a situation when
the users changed or deleted the records ?

Many thanks.





RE: Running an Update query before closing a form
Maurice 12/12/2008 1:06:03 PM
You can replace the button for code. In the close event of the form you can
place the following command:

Docmd.openquery [name of your updatequery here]

if you don't want the message to appear code it as follows

Docmd.SetWarnings false
Docmd.openquery [name of your updatequery here]
Docmd.setwarnings true

better yet if you want to trap any errors try the following

currentdb.execute [name of your updatequery here], dbfailonerror

If there is an error the query just won't execute.

hth
--
Maurice Ausum


"randria" wrote:

[Quoted Text]
> Hello everyone,
>
> I have form ( record sourece table1)that has a control (ctr1) whose value I
> need to update to a field in a different table ( table2). I have a command
> button that I have to click everytime before closing the form to run an
> update query so that the current value of ctr1 is copied to the field in
> table2.
> - It works fine when new records were posted. But when previous records were
> changed or deleted, it gives an error message ( the db couldn't run the
> update query and couldn t save all records because of various violations
> ....) .
> 2 questions:
> 1-is it possible to remove the command button and programmatically run
> the update query before closing ? I have not written an SQL in codes. I
> tried to copy the SQL from SQL View but I get errors.
>
> 2- What should I do before running the update query in a situation when
> the users changed or deleted the records ?
>
> Many thanks.
>
>
>
>
>
RE: Running an Update query before closing a form
randria 12/12/2008 7:09:01 PM
Hello Maurice,

Many thanks for your help, it is working perfectlly. The only part that I
could not fit in is the trapping of errors:
currentdb.execute [Query name],dbfailonerror-------> giving Run-time
error '3061' : ( too few parameters. Expected2.)

But without it, it works perfectly.
Many thanks.


"Maurice" wrote:

[Quoted Text]
> You can replace the button for code. In the close event of the form you can
> place the following command:
>
> Docmd.openquery [name of your updatequery here]
>
> if you don't want the message to appear code it as follows
>
> Docmd.SetWarnings false
> Docmd.openquery [name of your updatequery here]
> Docmd.setwarnings true
>
> better yet if you want to trap any errors try the following
>
> currentdb.execute [name of your updatequery here], dbfailonerror
>
> If there is an error the query just won't execute.
>
> hth
> --
> Maurice Ausum
>
>
> "randria" wrote:
>
> > Hello everyone,
> >
> > I have form ( record sourece table1)that has a control (ctr1) whose value I
> > need to update to a field in a different table ( table2). I have a command
> > button that I have to click everytime before closing the form to run an
> > update query so that the current value of ctr1 is copied to the field in
> > table2.
> > - It works fine when new records were posted. But when previous records were
> > changed or deleted, it gives an error message ( the db couldn't run the
> > update query and couldn t save all records because of various violations
> > ....) .
> > 2 questions:
> > 1-is it possible to remove the command button and programmatically run
> > the update query before closing ? I have not written an SQL in codes. I
> > tried to copy the SQL from SQL View but I get errors.
> >
> > 2- What should I do before running the update query in a situation when
> > the users changed or deleted the records ?
> >
> > Many thanks.
> >
> >
> >
> >
> >

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net