Run multiple SQL queries

K

Kurt

I need to run several update queries on one table. I
created a command button with a series of StrSql
statements behind it. When I click the button, it says
it's about to update the records, and when I click OK,
nothing happens. I check the table and nothing was
updated.

I read this article about running multiple Sql queries
(http://www.mvps.org/access/queries/qry0014.htm), but I'm
hoping there's a simpler solution using the command
button and underlying code.

Any ideas? Thanks. - Kurt (code below)

Private Sub cmdUpdate_Click()
On Error GoTo Err_Cancel

Dim StrSql As String

''''''''''''''''''''''''''''''''''''''''''''''

' Enter numidnew (numid in 000 format) value

StrSql = "UPDATE tblTeachersNew SET
tblTeachersNew.numidnew = " & _
"Format([numid],'000');"

''''''''''''''''''''''''''''''''''''''''''''''

' Enter RoomSort (RoomNumber in 000 format) value

StrSql = "UPDATE tblTeachersNew SET
tblTeachersNew.RoomSort = " & _
"IIf(IsNumeric([RoomNumber]),Format
([RoomNumber],'000'),[RoomNumber]) " & _
"WHERE (((tblTeachersNew.RoomNumber) Is Not Null));"

'''''''''''''''''''''''''''''''''''''''''''''''

' Enter TeachID (SchoolPrefix + numidnew) value

StrSql = "UPDATE tblTeachersNew SET
tblTeachersNew.TeachID = [SchoolPrefix] & [numidnew];"

'''''''''''''''''''''''''''''''''''''''''''''''

DoCmd.RunSQL StrSql

Exit_Cancel:
Exit Sub
Err_Cancel:
MsgBox Err.Number & Err.Description
Resume Exit_Cancel

Exit_cmdUpdate_Click:
Exit Sub

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top