473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help with message box

DP

hi,

i've got a price of code, which checks to see if a film is on rent, or
available. but how can i actualyl make the cancel button do somthing?
because, the cursor gets stuck on the filmID field. this is wat i've got so
far;

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False WHERE
FilmID=" & Me.FilmID
End Sub

how do i assign somthing to cancel? e.g. if the user clicks cancel,
everything it undone, and the cursor is not stuck in the filmID field.

TIA

dev

Feb 22 '06 #1
8 1961
The problem is that you've cancelled the update, which stops the entry from
being written to the table, but the control is still dirty. So, as soon as
you go to move off of the entry again, the code runs again. If the user
chooses to cancel you need to be able to pick up on their choice and undo
the selection.

If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another
FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"
You ask Yes or No, then don't do anything with the answer. Instead, try
this:

If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film
Entry") = vbYes Then
Me.FilmID.Undo
End If

Note that when the MsgBox is used this way, you have to enclose the
arguments in parentheses.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:N5******************@newsfe6-win.ntli.net...
hi,

i've got a price of code, which checks to see if a film is on rent, or
available. but how can i actualyl make the cancel button do somthing?
because, the cursor gets stuck on the filmID field. this is wat i've got
so
far;

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another
FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
WHERE
FilmID=" & Me.FilmID
End Sub

how do i assign somthing to cancel? e.g. if the user clicks cancel,
everything it undone, and the cursor is not stuck in the filmID field.

TIA

dev

Feb 22 '06 #2
DP wrote:
Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"
End If
Try this where you have your msgbox:

if MsgBox ("This Film is out on rent, Do you want to enter another
FilmID.", vbYesNo + vbInformation, "Duplicate Film Entry") = vbYes then

'do something for vbyes

else

'do soemthing for vbno

end if

Personally, I find these sorts of logic paths hard to implement in the
Before_Update event of a text box, but that's just me - others may be
able to help you more. I prefer the after update and would do something
like (air code):

Private Sub FilmID_AfterUpdate()

If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then

me.filmid = null

if MsgBox (me.FilmID & " is currently rented." & _
vbcrlf & vbcrlf & "Do you want to enter another FilmID?", _
vbOkCancel + vbQuestion, "Duplicate Film Entry") = vbOk then

'Do what ever it is you did in the first place, perhaps a pop up
or something to populate FilmID?

End If

End If

End Sub
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False WHERE
FilmID=" & Me.FilmID


Some of us warn strongly again using DoCmd.SetWarnings False. I find it
very dangerous and steer well clear of it - in your sample code, you
haven't turned them back on again, but doubtless you'll say "obviously
I'm going to change it!".

A safer way to do this is to use the DAO execute method with
dbfailonerror - I'm assuming you've A2003:

currentdb.execute "UPDATE tblFilm SET tblFilm.Available = Available
=False WHERE FilmID=" & Me.FilmID, dbFailOnError

This will bypass any advisory messages but will throw an error if your
SQL isn't correct.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Feb 22 '06 #3
DP
hi,

i've tried the code both of u have given me, and i get this error;

the microsoft jet database cannot find a record in the table tblFilm, with
key matching fields 'filmID.'

i understand wat u've tried to do, and i understand the problem.

i know y i get this error as well, its because, the subform has assigned the
record to the customer, as the membershipID field is still filled in.

i've got this code, which closes the form, but how do i stop the error from
popping up?

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then

Cancel = True
If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film
Entry ") = vbNo Then

DoCmd.Close

at this line;

CurrentDb.Execute "UPDATE tblFilm SET tblFilm.Available = Available =False
WHERE FilmID=" & Me.FilmID, dbFailOnError

End Sub

the above works, as it closes the form, which clears the subform as nothing
is added. but i can an error, at the line above. (Syntax error...)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:Yg*******************@newssvr21.news.prodigy. com...
The problem is that you've cancelled the update, which stops the entry from being written to the table, but the control is still dirty. So, as soon as
you go to move off of the entry again, the code runs again. If the user
chooses to cancel you need to be able to pick up on their choice and undo
the selection.

If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another
FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"


You ask Yes or No, then don't do anything with the answer. Instead, try
this:

If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film
Entry") = vbYes Then
Me.FilmID.Undo
End If

Note that when the MsgBox is used this way, you have to enclose the
arguments in parentheses.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:N5******************@newsfe6-win.ntli.net...

hi,

i've got a price of code, which checks to see if a film is on rent, or
available. but how can i actualyl make the cancel button do somthing?
because, the cursor gets stuck on the filmID field. this is wat i've got
so
far;

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another
FilmID.",
_
vbYesNo + vbInformation, "Duplicate Film Entry"
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
WHERE
FilmID=" & Me.FilmID
End Sub

how do i assign somthing to cancel? e.g. if the user clicks cancel,
everything it undone, and the cursor is not stuck in the filmID field.

TIA

dev


Feb 23 '06 #4
DP
lol.

i couldnt do it after an update, as the field would have already been
updated with other data.

the last part of the code i've got is fine. it updates another table
correctly.

its just the first bit i cant get to work, if a duplicate filmID is entered.
(i;ve tried using filmID = null and it dont work)

the best thing i can think of is to exit the form, and stop it from
displaying an error. is there anyway, u can disable the error popup that
displays?

dev

"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:dt**********@coranto.ucs.mun.ca...
DP wrote:
Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Do you want to enter another FilmID.", _
vbYesNo + vbInformation, "Duplicate Film Entry"
End If


Try this where you have your msgbox:

if MsgBox ("This Film is out on rent, Do you want to enter another
FilmID.", vbYesNo + vbInformation, "Duplicate Film Entry") = vbYes then

'do something for vbyes

else

'do soemthing for vbno

end if

Personally, I find these sorts of logic paths hard to implement in the
Before_Update event of a text box, but that's just me - others may be
able to help you more. I prefer the after update and would do something
like (air code):

Private Sub FilmID_AfterUpdate()

If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then

me.filmid = null

if MsgBox (me.FilmID & " is currently rented." & _
vbcrlf & vbcrlf & "Do you want to enter another FilmID?", _
vbOkCancel + vbQuestion, "Duplicate Film Entry") = vbOk then

'Do what ever it is you did in the first place, perhaps a pop up
or something to populate FilmID?

End If

End If

End Sub
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False WHERE FilmID=" & Me.FilmID


Some of us warn strongly again using DoCmd.SetWarnings False. I find it
very dangerous and steer well clear of it - in your sample code, you
haven't turned them back on again, but doubtless you'll say "obviously
I'm going to change it!".

A safer way to do this is to use the DAO execute method with
dbfailonerror - I'm assuming you've A2003:

currentdb.execute "UPDATE tblFilm SET tblFilm.Available = Available
=False WHERE FilmID=" & Me.FilmID, dbFailOnError

This will bypass any advisory messages but will throw an error if your
SQL isn't correct.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me

Feb 23 '06 #5
You may need to undo the entire record, not just the one control. If that's
the case, the syntax is

Me.Undo

When you go to close the form, it will try to save the record if you've made
changes. If the record is incomplete, you either need to complete it or undo
it.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:Rv*******************@newsfe7-gui.ntli.net...
hi,

i've tried the code both of u have given me, and i get this error;

the microsoft jet database cannot find a record in the table tblFilm, with
key matching fields 'filmID.'

i understand wat u've tried to do, and i understand the problem.

i know y i get this error as well, its because, the subform has assigned
the
record to the customer, as the membershipID field is still filled in.

i've got this code, which closes the form, but how do i stop the error
from
popping up?

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then

Cancel = True
If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film
Entry ") = vbNo Then

DoCmd.Close

at this line;

CurrentDb.Execute "UPDATE tblFilm SET tblFilm.Available = Available
=False
WHERE FilmID=" & Me.FilmID, dbFailOnError

End Sub

the above works, as it closes the form, which clears the subform as
nothing
is added. but i can an error, at the line above. (Syntax error...)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in
message
news:Yg*******************@newssvr21.news.prodigy. com...
The problem is that you've cancelled the update, which stops the entry

from
being written to the table, but the control is still dirty. So, as soon
as
you go to move off of the entry again, the code runs again. If the user
chooses to cancel you need to be able to pick up on their choice and undo
the selection.

> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
> Cancel = True
> MsgBox "This Film is out on rent, Do you want to enter another
> FilmID.",
> _
> vbYesNo + vbInformation, "Duplicate Film Entry"


You ask Yes or No, then don't do anything with the answer. Instead, try
this:

If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate
Film
Entry") = vbYes Then
Me.FilmID.Undo
End If

Note that when the MsgBox is used this way, you have to enclose the
arguments in parentheses.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:N5******************@newsfe6-win.ntli.net...
>
> hi,
>
> i've got a price of code, which checks to see if a film is on rent, or
> available. but how can i actualyl make the cancel button do somthing?
> because, the cursor gets stuck on the filmID field. this is wat i've
> got
> so
> far;
>
> Private Sub FilmID_BeforeUpdate(Cancel As Integer)
> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
> Cancel = True
> MsgBox "This Film is out on rent, Do you want to enter another
> FilmID.",
> _
> vbYesNo + vbInformation, "Duplicate Film Entry"
>
>
> End If
> DoCmd.SetWarnings False
> DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
> WHERE
> FilmID=" & Me.FilmID
>
>
> End Sub
>
> how do i assign somthing to cancel? e.g. if the user clicks cancel,
> everything it undone, and the cursor is not stuck in the filmID field.
>
> TIA
>
> dev
>
>
>



Feb 23 '06 #6
DP
thanx man.

at first that didint work, as i have this,

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Please Enter another FilmID.", _
vbOKOnly + vbInformation, "Duplicate Film Entry"

Me.Undo
End If
DoCmd.SetWarnings False
'DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False WHERE
FilmID=" & Me.FilmID
End Sub

but then i deleted the sql line, and moved it to 'after update' of filmID.
and it works.

i've got a delete button, and everytime i use it to delete a record, it has
this error;

runtime error 3197

The Microsoft Jet Database Engine stopped becasue you and another user are
attempting to change the same data at the same time.
how can i overcome this error, as if i close the DB, and then open it again,
it will delete the record, and update the correct field?? (currently i have
to press the delete button twice to delete a record)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:Ih******************@newssvr21.news.prodigy.c om...
You may need to undo the entire record, not just the one control. If that's the case, the syntax is

Me.Undo

When you go to close the form, it will try to save the record if you've made changes. If the record is incomplete, you either need to complete it or undo it.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:Rv*******************@newsfe7-gui.ntli.net...
hi,

i've tried the code both of u have given me, and i get this error;

the microsoft jet database cannot find a record in the table tblFilm, with key matching fields 'filmID.'

i understand wat u've tried to do, and i understand the problem.

i know y i get this error as well, its because, the subform has assigned
the
record to the customer, as the membershipID field is still filled in.

i've got this code, which closes the form, but how do i stop the error
from
popping up?

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then

Cancel = True
If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film Entry ") = vbNo Then

DoCmd.Close

at this line;

CurrentDb.Execute "UPDATE tblFilm SET tblFilm.Available = Available
=False
WHERE FilmID=" & Me.FilmID, dbFailOnError

End Sub

the above works, as it closes the form, which clears the subform as
nothing
is added. but i can an error, at the line above. (Syntax error...)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in
message
news:Yg*******************@newssvr21.news.prodigy. com...
The problem is that you've cancelled the update, which stops the entry

from
being written to the table, but the control is still dirty. So, as soon
as
you go to move off of the entry again, the code runs again. If the user
chooses to cancel you need to be able to pick up on their choice and undo the selection.
> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
> Cancel = True
> MsgBox "This Film is out on rent, Do you want to enter another
> FilmID.",
> _
> vbYesNo + vbInformation, "Duplicate Film Entry"

You ask Yes or No, then don't do anything with the answer. Instead, try
this:

If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate
Film
Entry") = vbYes Then
Me.FilmID.Undo
End If

Note that when the MsgBox is used this way, you have to enclose the
arguments in parentheses.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:N5******************@newsfe6-win.ntli.net...
>
> hi,
>
> i've got a price of code, which checks to see if a film is on rent, or > available. but how can i actualyl make the cancel button do somthing? > because, the cursor gets stuck on the filmID field. this is wat i've
> got
> so
> far;
>
> Private Sub FilmID_BeforeUpdate(Cancel As Integer)
> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
> Cancel = True
> MsgBox "This Film is out on rent, Do you want to enter another
> FilmID.",
> _
> vbYesNo + vbInformation, "Duplicate Film Entry"
>
>
> End If
> DoCmd.SetWarnings False
> DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
> WHERE
> FilmID=" & Me.FilmID
>
>
> End Sub
>
> how do i assign somthing to cancel? e.g. if the user clicks cancel,
> everything it undone, and the cursor is not stuck in the filmID field. >
> TIA
>
> dev
>
>
>



Feb 24 '06 #7
I'm guessing you still have the record locked from starting to edit it. You
aren't trying to delete the new record you just used undo on are you? If
it's an edited record, that's ok, but you can't delete a new record that
doesn't exist yet.

In your SQL, you have "SET tblFilm.Available = (Available =False)"
(parentheses added for clarification). This will essentially reverse the
value of Available. You could have said "SET tblFilm.Available = Not
Available" and it would do the same thing. If that's what you want or if it
was a type, that's ok, just checking.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:2Z*******************@newsfe6-win.ntli.net...
thanx man.

at first that didint work, as i have this,

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Please Enter another FilmID.", _
vbOKOnly + vbInformation, "Duplicate Film Entry"

Me.Undo
End If
DoCmd.SetWarnings False
'DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
WHERE
FilmID=" & Me.FilmID
End Sub

but then i deleted the sql line, and moved it to 'after update' of filmID.
and it works.

i've got a delete button, and everytime i use it to delete a record, it
has
this error;

runtime error 3197

The Microsoft Jet Database Engine stopped becasue you and another user are
attempting to change the same data at the same time.
how can i overcome this error, as if i close the DB, and then open it
again,
it will delete the record, and update the correct field?? (currently i
have
to press the delete button twice to delete a record)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in
message
news:Ih******************@newssvr21.news.prodigy.c om...
You may need to undo the entire record, not just the one control. If

that's
the case, the syntax is

Me.Undo

When you go to close the form, it will try to save the record if you've

made
changes. If the record is incomplete, you either need to complete it or

undo
it.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:Rv*******************@newsfe7-gui.ntli.net...
> hi,
>
> i've tried the code both of u have given me, and i get this error;
>
> the microsoft jet database cannot find a record in the table tblFilm, with > key matching fields 'filmID.'
>
> i understand wat u've tried to do, and i understand the problem.
>
> i know y i get this error as well, its because, the subform has
> assigned
> the
> record to the customer, as the membershipID field is still filled in.
>
> i've got this code, which closes the form, but how do i stop the error
> from
> popping up?
>
> Private Sub FilmID_BeforeUpdate(Cancel As Integer)
> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>
> Cancel = True
> If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate Film > Entry ") = vbNo Then
>
> DoCmd.Close
>
> at this line;
>
> CurrentDb.Execute "UPDATE tblFilm SET tblFilm.Available = Available
> =False
> WHERE FilmID=" & Me.FilmID, dbFailOnError
>
> End Sub
>
> the above works, as it closes the form, which clears the subform as
> nothing
> is added. but i can an error, at the line above. (Syntax error...)
>
> thanx
>
> dev
>
>
> "Wayne Morgan" <co***************************@hotmail.com> wrote in
> message
> news:Yg*******************@newssvr21.news.prodigy. com...
>> The problem is that you've cancelled the update, which stops the entry
> from
>> being written to the table, but the control is still dirty. So, as
>> soon
>> as
>> you go to move off of the entry again, the code runs again. If the
>> user
>> chooses to cancel you need to be able to pick up on their choice and undo >> the selection.
>>
>>
>> > If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>> > Cancel = True
>> > MsgBox "This Film is out on rent, Do you want to enter another
>> > FilmID.",
>> > _
>> > vbYesNo + vbInformation, "Duplicate Film Entry"
>>
>> You ask Yes or No, then don't do anything with the answer. Instead,
>> try
>> this:
>>
>> If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate
>> Film
>> Entry") = vbYes Then
>> Me.FilmID.Undo
>> End If
>>
>> Note that when the MsgBox is used this way, you have to enclose the
>> arguments in parentheses.
>>
>> --
>> Wayne Morgan
>> MS Access MVP
>>
>>
>> "DP" <DP@hotmail.com> wrote in message
>> news:N5******************@newsfe6-win.ntli.net...
>> >
>> > hi,
>> >
>> > i've got a price of code, which checks to see if a film is on rent, or >> > available. but how can i actualyl make the cancel button do somthing? >> > because, the cursor gets stuck on the filmID field. this is wat i've
>> > got
>> > so
>> > far;
>> >
>> > Private Sub FilmID_BeforeUpdate(Cancel As Integer)
>> > If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>> > Cancel = True
>> > MsgBox "This Film is out on rent, Do you want to enter another
>> > FilmID.",
>> > _
>> > vbYesNo + vbInformation, "Duplicate Film Entry"
>> >
>> >
>> > End If
>> > DoCmd.SetWarnings False
>> > DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available
>> > =False
>> > WHERE
>> > FilmID=" & Me.FilmID
>> >
>> >
>> > End Sub
>> >
>> > how do i assign somthing to cancel? e.g. if the user clicks cancel,
>> > everything it undone, and the cursor is not stuck in the filmID field. >> >
>> > TIA
>> >
>> > dev
>> >
>> >
>> >
>>
>>
>
>



Feb 24 '06 #8
DP
thanx, i sorted everything now. i appreciate all the help.

thanx again

dev

"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:sN******************@newssvr25.news.prodigy.n et...
I'm guessing you still have the record locked from starting to edit it. You aren't trying to delete the new record you just used undo on are you? If
it's an edited record, that's ok, but you can't delete a new record that
doesn't exist yet.

In your SQL, you have "SET tblFilm.Available = (Available =False)"
(parentheses added for clarification). This will essentially reverse the
value of Available. You could have said "SET tblFilm.Available = Not
Available" and it would do the same thing. If that's what you want or if it was a type, that's ok, just checking.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:2Z*******************@newsfe6-win.ntli.net...
thanx man.

at first that didint work, as i have this,

Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
Cancel = True
MsgBox "This Film is out on rent, Please Enter another FilmID.", _
vbOKOnly + vbInformation, "Duplicate Film Entry"

Me.Undo
End If
DoCmd.SetWarnings False
'DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available =False
WHERE
FilmID=" & Me.FilmID
End Sub

but then i deleted the sql line, and moved it to 'after update' of filmID. and it works.

i've got a delete button, and everytime i use it to delete a record, it
has
this error;

runtime error 3197

The Microsoft Jet Database Engine stopped becasue you and another user are attempting to change the same data at the same time.
how can i overcome this error, as if i close the DB, and then open it
again,
it will delete the record, and update the correct field?? (currently i
have
to press the delete button twice to delete a record)

thanx

dev
"Wayne Morgan" <co***************************@hotmail.com> wrote in
message
news:Ih******************@newssvr21.news.prodigy.c om...
You may need to undo the entire record, not just the one control. If

that's
the case, the syntax is

Me.Undo

When you go to close the form, it will try to save the record if you've

made
changes. If the record is incomplete, you either need to complete it or

undo
it.

--
Wayne Morgan
MS Access MVP
"DP" <DP@hotmail.com> wrote in message
news:Rv*******************@newsfe7-gui.ntli.net...
> hi,
>
> i've tried the code both of u have given me, and i get this error;
>
> the microsoft jet database cannot find a record in the table tblFilm,

with
> key matching fields 'filmID.'
>
> i understand wat u've tried to do, and i understand the problem.
>
> i know y i get this error as well, its because, the subform has
> assigned
> the
> record to the customer, as the membershipID field is still filled in.
>
> i've got this code, which closes the form, but how do i stop the error > from
> popping up?
>
> Private Sub FilmID_BeforeUpdate(Cancel As Integer)
> If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>
> Cancel = True
> If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate

Film
> Entry ") = vbNo Then
>
> DoCmd.Close
>
> at this line;
>
> CurrentDb.Execute "UPDATE tblFilm SET tblFilm.Available = Available
> =False
> WHERE FilmID=" & Me.FilmID, dbFailOnError
>
> End Sub
>
> the above works, as it closes the form, which clears the subform as
> nothing
> is added. but i can an error, at the line above. (Syntax error...)
>
> thanx
>
> dev
>
>
> "Wayne Morgan" <co***************************@hotmail.com> wrote in
> message
> news:Yg*******************@newssvr21.news.prodigy. com...
>> The problem is that you've cancelled the update, which stops the entry > from
>> being written to the table, but the control is still dirty. So, as
>> soon
>> as
>> you go to move off of the entry again, the code runs again. If the
>> user
>> chooses to cancel you need to be able to pick up on their choice and

undo
>> the selection.
>>
>>
>> > If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>> > Cancel = True
>> > MsgBox "This Film is out on rent, Do you want to enter another
>> > FilmID.",
>> > _
>> > vbYesNo + vbInformation, "Duplicate Film Entry"
>>
>> You ask Yes or No, then don't do anything with the answer. Instead,
>> try
>> this:
>>
>> If MsgBox("This Film is out....", vbYesNo + vbInformation, "Duplicate >> Film
>> Entry") = vbYes Then
>> Me.FilmID.Undo
>> End If
>>
>> Note that when the MsgBox is used this way, you have to enclose the
>> arguments in parentheses.
>>
>> --
>> Wayne Morgan
>> MS Access MVP
>>
>>
>> "DP" <DP@hotmail.com> wrote in message
>> news:N5******************@newsfe6-win.ntli.net...
>> >
>> > hi,
>> >
>> > i've got a price of code, which checks to see if a film is on rent,
or
>> > available. but how can i actualyl make the cancel button do

somthing?
>> > because, the cursor gets stuck on the filmID field. this is wat

i've >> > got
>> > so
>> > far;
>> >
>> > Private Sub FilmID_BeforeUpdate(Cancel As Integer)
>> > If DCount("*", "tblFilmRental", "FilmID=" & Me![FilmID]) > 0 Then
>> > Cancel = True
>> > MsgBox "This Film is out on rent, Do you want to enter another
>> > FilmID.",
>> > _
>> > vbYesNo + vbInformation, "Duplicate Film Entry"
>> >
>> >
>> > End If
>> > DoCmd.SetWarnings False
>> > DoCmd.RunSQL "UPDATE tblFilm SET tblFilm.Available = Available
>> > =False
>> > WHERE
>> > FilmID=" & Me.FilmID
>> >
>> >
>> > End Sub
>> >
>> > how do i assign somthing to cancel? e.g. if the user clicks cancel, >> > everything it undone, and the cursor is not stuck in the filmID

field.
>> >
>> > TIA
>> >
>> > dev
>> >
>> >
>> >
>>
>>
>
>



Feb 28 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
2
by: fabien | last post by:
Hi, I am writing a POV-RAY editor with Python using either QT or GTK as GUI 'wrapper'. ( I am still trying both ) * * * * PYGTK * * * * I have downloaded PygtkScintilla-1.99.5. There is a...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.