Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

Update SQL Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Emma Aumack - 28 Jun 2007 18:34 GMT
Hello all,

Trying to code a "clear" flag field button on a form using Update SQL
statement.  Please see the following 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.  i.e.",
"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

Can someone tell me what is wrong with the SQL statement?  Maybe quotes in
the wrong place?  
Signature

www.bardpv.com
Tempe, Arizona

Ofer Cohen - 28 Jun 2007 19:04 GMT
There are few things that I can see
1. I can't see which value you are setting the Tbl_Contacts.Flag
2. Missing spaces for each line
3. If it a string field you need to add single quote

' For number
"UPDATE Tbl_Contacts SET Tbl_Contacts.FileName = " & SomeValue & " WHERE " & _
" Tbl_Contacts.FileName =  " & SomeValue

' For text
"UPDATE Tbl_Contacts SET Tbl_Contacts.FileName = '" & SomeValue & "' WHERE "
& _
" Tbl_Contacts.FileName =  '" & SomeValue & "'"

If you need more help, I need to know the field type and which value you
want to assign in the update
Signature

Good Luck
BS"D

> Hello all,
>
[quoted text clipped - 35 lines]
> Can someone tell me what is wrong with the SQL statement?  Maybe quotes in
> the wrong place?  
Emma Aumack - 28 Jun 2007 20:40 GMT
Thanks Ofer,

Both the flgFieldNo and the txtFlgField are text that are input by the user.
I am doing it this way because I have 9 flag fields and I don't want to have
to program a button for each flag field.

I tried to update the code but am failing miserably.  Still getting the
syntax error in UPDATE Statement message.

Here is my 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.  i.e.",
"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

Can you please help.

Signature

www.bardpv.com
Tempe, Arizona

> There are few things that I can see
> 1. I can't see which value you are setting the Tbl_Contacts.Flag
[quoted text clipped - 52 lines]
> > Can someone tell me what is wrong with the SQL statement?  Maybe quotes in
> > the wrong place?  
Ofer Cohen - 28 Jun 2007 20:58 GMT
Try

strSQL = "UPDATE Tbl_Contacts SET Tbl_Contacts.Flag" & flgFieldNo & _
" = '' WHERE ((Tbl_Contacts.Flag" & flgFieldNo & ") = '" & txtFlgfield & "')"

Assuming that you want to update the field with empty value

Signature

Good Luck
BS"D

> Thanks Ofer,
>
[quoted text clipped - 97 lines]
> > > Can someone tell me what is wrong with the SQL statement?  Maybe quotes in
> > > the wrong place?  
Emma Aumack - 28 Jun 2007 21:20 GMT
YES!!!!!  Success!! Thank you!  I'm going to save this and study it thoroughly!
Signature

www.bardpv.com
Tempe, Arizona

> Try
>
[quoted text clipped - 104 lines]
> > > > Can someone tell me what is wrong with the SQL statement?  Maybe quotes in
> > > > the wrong place?  
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.