
Signature
www.bardpv.com
Tempe, Arizona
Is there any chance the current record in the form might be unsaved?
Assuming your form is bound, try inserting this code on a new line after the
DIM line:
If Me.Dirty Then Me.Dirty = False
Instead of OpenQuery, you could also try this:
dbEngine(0)(0).Execute stDocName, dbFailOnError
which should notify you if the query is not able to update all the records.
For an explanation of this, see:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Hi All,
>
[quoted text clipped - 35 lines]
>
> Emma
Naeem Azizian - 28 Jun 2007 07:46 GMT
> Is there any chance the current record in the form might be unsaved?
>
[quoted text clipped - 57 lines]
> >www.bardpv.com
> > Tempe, Arizona
First save the record and then do what you want to do,
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
when you don't save the record, it will load the old data from the
table and will not notice the changes you made in the form.
Emma Aumack - 28 Jun 2007 17:38 GMT
Thank you Allen!
I like your code much better. However, I am getting an error in the SQL
Update statement. Think you could help me out? Quotations just kill me.
Please see the updated code below:
Private Sub btn_ClFlag_Click()
On Error GoTo Err_btn_ClFlag_Click
Dim strSQL As String
Dim flgField As String
flgField = InputBox("Enter Flag #:", "Flag Field")
txtFlgfield = InputBox("Enter Flag Criteria to be Cleared. i.e.",
"Clear Flag" & flgField)
If Me.Dirty Then
Me.Dirty = False
End If
strSQL = "UPDATE Tbl_Contacts SET Tbl_Contacts.Flag" & _
flgField & "WHERE (((Tbl_Contacts.Flag" & flgField & ") = " &
txtFlgField & "));"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Me.Requery
Exit_btn_ClFlag_Click:
Exit Sub
Err_btn_ClFlag_Click:
msgbox Err.Description
Resume Exit_btn_ClFlag_Click
End Sub
Thank you again!

Signature
www.bardpv.com
Tempe, Arizona
> Is there any chance the current record in the form might be unsaved?
>
[quoted text clipped - 49 lines]
> >
> > Emma
Allen Browne - 28 Jun 2007 18:26 GMT
To get a sample SQL statement, you can mock up a query and switch to SQL
View (View menu.)
For an explanation of how to handle the quotes, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Thank you Allen!
>
[quoted text clipped - 93 lines]
>> >
>> > Emma
Emma Aumack - 28 Jun 2007 18:50 GMT
Hi Allen,
That's where I got this SQL statement. but I've modified it to allow the
user to enter in parameters, so that I don't have to have a Clear button for
each of the 9 Flag fields. This way the user selects the Flag field they
want to clear then enters the flag text they want cleared in that flag field.
However, I am getting the Update syntax error message and I can't figure out
why.

Signature
www.bardpv.com
Tempe, Arizona
> To get a sample SQL statement, you can mock up a query and switch to SQL
> View (View menu.)
[quoted text clipped - 101 lines]
> >> >
> >> > Emma
Emma Aumack - 28 Jun 2007 19:02 GMT
Okay, I think I've figured out the SQL statement error. I had not told the
Update query what to SET the text in the txtFlgField to.
But now I'm getting the error:
"Too Few parameters. Expected 1" when I put a "1" in the flgFieldNo
inputbox and some text to be cleared in the txtFlgField input box.
Is my inputbox code right?
Again, here is the updated code:
Private Sub btn_ClFlag_Click()
On Error GoTo Err_btn_ClFlag_Click
Dim strSQL As String
Dim flgFieldNo As String
Dim txtFlgfield As String
flgFieldNo = InputBox("Enter Flag #:", "Flag Field")
txtFlgfield = InputBox("Enter Flag Criteria to be Cleared.", "Clear
Flag" & flgFieldNo)
If Me.Dirty Then
Me.Dirty = False
End If
strSQL = "UPDATE Tbl_Contacts SET Tbl_Contacts.Flag" & _
flgFieldNo & " ="""" WHERE ((Tbl_Contacts.Flag" & flgFieldNo & ") =
" & txtFlgfield & ");"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Me.Requery
Exit_btn_ClFlag_Click:
Exit Sub
Err_btn_ClFlag_Click:
msgbox Err.Description
Resume Exit_btn_ClFlag_Click
End Sub

Signature
www.bardpv.com
Tempe, Arizona
> Hi Allen,
>
[quoted text clipped - 110 lines]
> > >> >
> > >> > Emma
Emma Aumack - 28 Jun 2007 22:42 GMT
Got it working! Thanks for your help

Signature
www.bardpv.com
Tempe, Arizona
> Hi Allen,
>
[quoted text clipped - 110 lines]
> > >> >
> > >> > Emma