Access VBA Findfirst with Dlookup Syntax Error - ms-access

I am getting an error Syntax Error(Missing Operator) in expression for this piece of code
For i = 0 To Me.listMachineSubSystem.ListCount - 1
rs.FindFirst "[Machine ID]=" & ID & "[MachineSystem]=" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i))
rs1.AddNew
rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(1, i)
rs1![Machine Sytem ID] = rs![Machine System ID]
rs1.Update
Next i

You need to account for spacing, use the AND keyword when checking multiple conditions, and use delimiters where needed (strings).
If MachineSystem is a number:
rs.FindFirst "[Machine ID]= " & ID & " AND [MachineSystem]=" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i))
If MachineSystem is a string:
rs.FindFirst "[Machine ID]= " & ID & " AND [MachineSystem]= '" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i)) & "'"

Related

Access VBA: Eliminating FindFirst Looping Duplication

i have 4 listboxes named listMachine, listMachineSystem,listMachineSubSystem and listcompoenents. The user selects the items the from the list boxes as he wishes and the tables are populated along with the ID from the previuos table to the new table since all the listboxes are connected hierarchially. The problem is that in the tblcomponents the seleted items get popileuted in a loop over and over agao an i dont how to stop this . I have attahced the code below . Can anyone help me out on this.
ID = DMax("[MAchine ID]", "tblmachine")
Dim sMachineSubsystem As String, varSelectedID11 As Variant
Dim vMaxMachineSubsystemID As Variant
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblMachineSystem", dbOpenDynaset, dbAppendOnly)
Set rs1 = db.OpenRecordset("tblMachineSubSystem", dbOpenDynaset, dbAppendOnly)
Set rs2 = db.OpenRecordset("tblComponents", dbOpenDynaset, dbAppendOnly)
For n = 0 To Me.listMachineSystem.ListCount - 1
If Me.listMachineSystem.Selected(n) Then
rs.AddNew
rs!MachineSystem = Me.listMachineSystem.Column(0, n)
rs![MAchine ID] = ID
rs!MO_TAG = Me.listMachineSystem.Column(3, n)
rs!MachineSystem_Details = Me.listMachineSystem.Column(4, n)
rs.Update
End If
Next n
For i = 0 To Me.listMachineSubSystem.ListCount - 1
If Me.listMachineSubSystem.Selected(i) Then
rs.FindFirst "[Machine ID]=" & ID & " AND [MachineSystem]= '" &
DLookup ("[MachineSystem]", "tblMachineSystem",
"[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i)) & "'"
rs1.AddNew
rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(0, i)
rs1![Machine Sytem ID] = rs![Machine System ID]
rs1![MO_TAG] = Me.listMachineSubSystem.Column(3, i)
rs1![MachineSubSystem_Details] = Me.listMachineSubSystem.Column(4, i)
rs1.Update
'add selected value(s) from listComponents to tblComponents
For l = 0 To Me.listComponents.ListCount - 1
If Me.listComponents.Selected(l) Then
varSelectedID2 = Me.listComponents.Column(2, l)
sMachineSubsystem = DLookup("[MachineSubsystem]", "tblMachineSubSystem",
"[Machine Subsystem ID]=" & varSelectedID2)
vMaxMachineSubsystemID = DMax("[Machine System ID]", "tblMachineSystem",
"[Machine ID]=" & ID & " AND [MachineSystem]= '" &
DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]="
& rs![Machine System ID]) & "'")
rs1.FindFirst "[Machine Sytem ID]=" & vMaxMachineSubsystemID & "
AND [MachineSubsystem]= '" & sMachineSubsystem & "'"
If rs1.NoMatch Then
MsgBox "no records found"
Else
Do While Not rs1.NoMatch
MsgBox "I found it!!!"
rs2.AddNew
rs2![Components] = Me.listComponents.Column(0, l)
rs2![Machine Subsystem ID] = rs1![Machine Subsystem ID]
rs2![MO_TAG] = Me.listComponents.Column(3, l)
rs2![Components_Detail] = Me.listComponents.Column(4, l)
rs2.Update
rs1.FindNext "[Machine Sytem ID]=" & vMaxMachineSubsystemID & "
AND [MachineSubsystem]= '" & sMachineSubsystem & "'"
Loop
End If
End If
Next l
End If
Next i

FindFirst to search for multiple values

I have a listbox named listcomponents and each time the user can select multiple values. When the user selects the listbox the Findfirst operation is carried and the Machine System ID and the MachineSubsystem is calculated and based on these two the rs1![Machine Subsystem ID] is obtained. The value obtained in rs1![Machine Subsystem ID] is then again used in the condition for the next list box.
The problem is that the FindFirst operation only checks for the last stored value in rs1![Machine Subsystem ID] and not all the values which get generated (maybe because only the last value is stored in it). So is there a way I can get this to check for all the values that get generated in rs1![Machine Subsystem ID]. Here is the code:
ID = DMax("[MAchine ID]", "tblmachine")
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblMachineSystem", dbOpenDynaset, dbAppendOnly)
Set rs1 = db.OpenRecordset("tblMachineSubSystem", dbOpenDynaset,
dbAppendOnly)
Set rs2 = db.OpenRecordset("tblComponents", dbOpenDynaset, dbAppendOnly)
Set rsmas = db.OpenRecordset("tblMasterData", dbOpenDynaset, dbAppendOnly)
'add selected value(s) to table
Set ctl = Me.listMachineSystem
Set ctl1 = Me.listMachineSubSystem
Set ctl2 = Me.listComponents
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!MachineSystem = ctl.ItemData(varItem)
rs![MAchine ID] = ID
rs.Update
Next varItem
For i = 0 To Me.listMachineSubSystem.ListCount - 1
If Me.listMachineSubSystem.Selected(i) Then
rs.FindFirst "[Machine ID]=" & ID & " AND [MachineSystem]= '" & DLookup("
[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" &
Me.listMachineSubSystem.Column(2, i)) & "'"
rs1.AddNew
rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(0, i)
rs1![Machine Sytem ID] = rs![Machine System ID]
rs1.Update
End If
Next i
For i = 0 To Me.listComponents.ListCount - 1
If Me.listComponents.Selected(i) Then
rs1.FindFirst "[Machine Sytem ID]=" & rs![Machine System ID] & " AND
[MachineSubsystem]= '" & DLookup("[MachineSubsystem]",
"tblMachineSubSystem",
"[Machine Subsystem ID]=" & Me.listComponents.Column(2, i)) & "'"
If rs1.NoMatch Then
MsgBox "no records found"
Else
Do While Not rs1.NoMatch
MsgBox "i found it!!!"
rs1.FindNext "[Machine Sytem ID]=" & rs![Machine System ID] & "
AND [MachineSubsystem]= '" & DLookup("[MachineSubsystem]",
"tblMachineSubSystem", "[Machine Subsystem ID]=" &
Me.listComponents.Column(2, i)) & "'"
Loop
rs1.FindNext "[Machine Sytem ID]=" & rs![Machine System ID] & " AND
[MachineSubsystem]= '" & DLookup("[MachineSubsystem]",
"tblMachineSubSystem", "[Machine Subsystem ID]=" &
Me.listComponents.Column(2, i)) & "'"
End If
rs2.AddNew
rs2![Components] = Me.listComponents.Column(0, i)
rs2![Machine Subsystem ID] = rs1![Machine Subsystem ID]
rs2.Update
End If
Next i
I have two tables tblmMchineSubSystem with fiels and tblComponents and when the above code runs, I want the Machine Subsystem ID which is the primary key of tblmMchineSubSystem to be populated into the Machine Subsystem ID field of tblComponents. The problem with the above code is that only the last value from the rs![Machine System ID] is checked in the findfirst function. I want all the values in rs![Machine System ID] to be checked by the FindFirst function.
The NEW CODE
ID = DMax("[MAchine ID]", "tblmachine")
Dim sMachineSubsystem As String, varSelectedID11 As Variant
Dim vMaxMachineSubsystemID As Variant
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblMachineSystem", dbOpenDynaset, dbAppendOnly)
Set rs1 = db.OpenRecordset("tblMachineSubSystem", dbOpenDynaset,
dbAppendOnly)
Set rs2 = db.OpenRecordset("tblComponents", dbOpenDynaset, dbAppendOnly)
Set rsmas = db.OpenRecordset("tblMasterData", dbOpenDynaset, dbAppendOnly)
Set ctl = Me.listMachineSystem
Set ctl1 = Me.listMachineSubSystem
Set ctl2 = Me.listComponents
'add selected value(s) from listMachineSystem to tblMachineSystem
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!MachineSystem = ctl.ItemData(varItem)
rs![MAchine ID] = ID
rs.Update
Next varItem
For i = 0 To Me.listMachineSubSystem.ListCount - 1
If Me.listMachineSubSystem.Selected(i) Then
rs.FindFirst "[Machine ID]=" & ID & " AND [MachineSystem]= '" & DLookup("
[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" &
Me.listMachineSubSystem.Column(2, i)) & "'"
rs1.AddNew
rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(0, i)
rs1![Machine Sytem ID] = rs![Machine System ID]
rs1.Update
'Grab the maximum Machine System ID for the last selected item in the
listMachineSubSystem list, for use in the next section
'To add components for every item selected in listMachineSubSystem, move the
entire below section of code to inside the previous section (so it's a loop
within a loop... be sure to rename i to something else)
vMaxMachineSubsystemID = DMax("[Machine System ID]", "tblMachineSystem", "
[Machine ID]=" & ID & " AND [MachineSystem]= '" & DLookup("
[MachineSystem]",
"tblMachineSystem", "[Machine System ID]=" & rs![Machine System ID]) & "'")
'add selected value(s) from listComponents to tblComponents
For l = 0 To Me.listComponents.ListCount - 1
If Me.listComponents.Selected(l) Then
varSelectedID2 = Me.listComponents.Column(2, l)
sMachineSubsystem = DLookup("[MachineSubsystem]",
"tblMachineSubSystem", "[Machine Subsystem ID]=" & varSelectedID2)
rs1.FindFirst "[Machine Sytem ID]=" & vMaxMachineSubsystemID & " AND
[MachineSubsystem]= '" & sMachineSubsystem & "'"
If rs1.NoMatch Then
MsgBox "no records found"
Else
Do While Not rs1.NoMatch
MsgBox "I found it!!!"
rs2.AddNew
rs2![Components] = Me.listComponents.Column(0, l)
rs2![Machine Subsystem ID] = rs1![Machine Subsystem ID]
rs2.Update
rs1.FindNext "[Machine Sytem ID]=" & vMaxMachineSubsystemID & "
AND [MachineSubsystem]= '" & sMachineSubsystem & "'"
Loop
End If
End If
Next l
End If
Next i
I'm assuming you set rs (without 1 or 2) to something earlier?
This seems very convoluted, and would result in a lot of unnecessary work for the machine. I'd add a TransactionID to the tblMachineSubSystem table, and then do something like:
dim MachineSystemID as variant, iMaxTransactionID as integer, iNewTransactionID as integer
Set rs1 = db.OpenRecordset("SELECT * FROM tblMachineSubSystem WHERE [Machine Sytem ID] = 1", dbOpenDynaset, dbAppendOnly) 'Saves time when all you want to do is add to the table
For i = 0 To Me.listMachineSubSystem.ListCount - 1
If Me.listMachineSubSystem.Selected(i) Then
MachineSystemID = DLookup("[Machine System ID]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i))
iMaxTransactionID = DMax("[TransactionID]", "tblMachineSystem") 'Note that this logic assumes a single-user database, so there aren't multiple transactions going on at the same time
rs1.AddNew
rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(0, i)
rs1![Machine Sytem ID] = rs![Machine System ID]
iNewTransactionID = iMaxTransactionID + 1
rs1![TransactionID] = iNewTransactionID
rs1.Update
End If
Next i
rs1.Close
docmd.runsql "INSERT INTO tblComponents (Components, [Machine Subsystem ID]) SELECT MachineSubsystem, [Machine Subsystem ID] FROM tblMachineSubSystem WHERE TransactionID = " & iNewTransactionID
EDIT: Ok, here's the new version:
ID = DMax("[MAchine ID]", "tblmachine")
dim sMachineSubsystem as string, varSelectedID11 as variant
dim vMaxMachineSubsystemID as variant
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblMachineSystem", dbOpenDynaset, dbAppendOnly)
Set rs1 = db.OpenRecordset("tblMachineSubSystem", dbOpenDynaset,
dbAppendOnly)
Set rs2 = db.OpenRecordset("tblComponents", dbOpenDynaset, dbAppendOnly)
Set rsmas = db.OpenRecordset("tblMasterData", dbOpenDynaset, dbAppendOnly)
Set ctl = Me.listMachineSystem
Set ctl1 = Me.listMachineSubSystem
Set ctl2 = Me.listComponents
'add selected value(s) from listMachineSystem to tblMachineSystem
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!MachineSystem = ctl.ItemData(varItem)
rs![MAchine ID] = ID
rs.Update
Next varItem
'add selected value(s) from listMachineSubSystem to tblMachineSubSystem
For i = 0 To Me.listMachineSubSystem.ListCount - 1
If Me.listMachineSubSystem.Selected(i) Then
varSelectedID1 = Me.listMachineSubSystem.Column(2, i)
sMachineSubsystem = Me.listMachineSubSystem.Column(0, i)
rs1.AddNew
rs1![MachineSubsystem] = sMachineSubsystem
rs1![Machine Sytem ID] = varSelectedID1
rs1.Update
End If
Next i
'Grab the maximum Machine System ID for the last selected item in the listMachineSubSystem list, for use in the next section
'To add components for every item selected in listMachineSubSystem, move the entire below section of code to inside the previous section (so it's a loop within a loop... be sure to rename i to something else)
vMaxMachineSubsystemID = DMax("[Machine System ID]", "tblMachineSystem", "[Machine ID]=" & ID & " AND [MachineSystem]= '" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & varSelectedID1) & "'")
'add selected value(s) from listComponents to tblComponents
For i = 0 To Me.listComponents.ListCount - 1
If Me.listComponents.Selected(i) Then
varSelectedID2 = Me.listComponents.Column(2, i)
sMachineSubsystem = DLookup("[MachineSubsystem]", "tblMachineSubSystem", "[Machine Subsystem ID]=" & varSelectedID2)
rs1.FindFirst "[Machine Sytem ID]=" & vMaxMachineSubsystemID & " AND [MachineSubsystem]= '" & sMachineSubsystem & "'"
If rs1.NoMatch Then
MsgBox "no records found"
Else
Do While Not rs1.NoMatch
MsgBox "I found it!!!"
rs2.AddNew
rs2![Components] = Me.listComponents.Column(0, i)
rs2![Machine Subsystem ID] = rs1![Machine Subsystem ID]
rs2.Update
rs1.FindNext "[Machine Sytem ID]=" & vMaxMachineSubsystemID & " AND [MachineSubsystem]= '" & sMachineSubsystem & "'"
Loop
End If
End If
Next i

Access 2013 Edit Form error 3021

So I've got the code below (not all of it is grey for some reason)
Private Sub CmdEdit_Click()
Me.Tableinform.Requery
Dim rs As DAO.Recordset
Set rs = Me.Tableinform.Form.RecordsetClone
'get data to textbox control
With rs
If .RecordCount > 0 Then
With Me.Tableinform.Form.Recordset
Me.ShowIDbox = .Fields("[ID]").Value
Me.CompbyDD = .Fields("[Received By]")
Me.Date1 = .Fields("[Date Received]")
Me.Date2 = .Fields("[Date Processed]")
Me.ReqType = .Fields("[Request Type]")
Me.InsName = .Fields("[Insured Name]")
Me.RiskNo = .Fields("[Risk Number]")
Me.EndtRef = .Fields("[Endorsement Reference]")
Me.EOCNo = .Fields("[EOC Number]")
Me.Tech = .Fields("[Technician]")
Me.BillIns = .Fields("[Billing Instructions]")
Me.Addrecord.Caption = "Update"
Me.CmdEdit.Enabled = False
Me.cmdDuplicate.Enabled = True
Me.CmdDelete.Enabled = True
End With
End If
End With
End Sub
After one Edit and Update, the edit function throws out Error '3021' No Current Record?
Please show me where I am going wrong with this.
Add/Update button as follows:
If Me.ShowIDbox.Value = "" Then
CurrentDb.Execute "INSERT INTO fmdatatable( [Received By], [Date Received], [Date Processed], [Request Type], [Insured Name], [Risk Number], [Endorsement Reference], [EOC Number], [Technician], [Billing Instructions]) " & _
" VALUES ('" & Me.CompbyDD & "','" & Me.Date1 & "','" & Me.Date2 & "','" & Me.ReqType & "','" & Me.InsName & "','" & Me.RiskNo & "','" & Me.EndtRef & "','" & Me.EOCNo & "','" & Me.Tech & "','" & Me.BillIns & "')"
Else
CurrentDb.Execute "UPDATE fmdatatable SET [Received By]='" & Me.CompbyDD & "'" & _
", [Date Received]='" & Me.Date1 & "'" & _
", [Date Processed]='" & Me.Date2 & "'" & _
", [Request Type]='" & Me.ReqType & "'" & _
", [Insured Name]='" & Me.InsName & "'" & _
", [Risk Number]='" & Me.RiskNo & "'" & _
", [Endorsement Reference]='" & Me.EndtRef & "'" & _
", [EOC Number]='" & Me.EOCNo & "'" & _
", [Technician]='" & Me.Tech & "'" & _
", [Billing Instructions]='" & BillIns & "'" & _
" WHERE [ID]=" & Me.ShowIDbox.Value
End If
Me.CompbyDD = "-Please Select-"
Me.Date1 = ""
Me.Date2 = ""
Me.ReqType = "-Please Select-"
Me.InsName = ""
Me.RiskNo = ""
Me.EndtRef = ""
Me.EOCNo = ""
Me.Tech = ""
Me.BillIns = "-Please Select-"
Me.ShowIDbox = ""
Me.Addrecord.Caption = "Add Record"
Me.CmdEdit.Enabled = True
Me.cmdDuplicate.Enabled = False
Me.CmdDelete.Enabled = False
Tableinform.Form.Requery
This edit works once, then all subsequent later edits are throwing errors out.

Ignore connection error on OBDC query

I have a query that that connects to several remote machines to union data into a single table. It works fine when all the machines are connected but occasionally any given machine may be turned off (which results in error), I'd like my query to ignore any connections that are unavailable and continue with the rest of the query. Is there any way to do this?
I'm using linked tables with an OBDC conncetion (driver: MySql ODBC 5.3 Ansi Driver)
Here is my query:
SELECT "HX32" AS workcenter, "HX32." & [HX32].[dataid] AS tbldataid, HX32.dataid AS dataid, HX32.TS, DMin("[TS]","[HX32]","[TS] > #" & [TS] & "#") AS EndTS, DateDiff("s",[TS],EndTS) AS durationsec, Format(Int([durationsec]/86400)) & " " & Format([durationsec]/86400,"hh:nn:ss") AS duration, Format(TS,"mm/dd/yyyy") AS [Day], Switch(incycle=0,'Down',incycle=1,'Running') AS Status
FROM HX32
WHERE (((HX32.TS)>Date()-3) AND ((HX32.incycle)=0))
UNION ALL
SELECT "VL65A" AS workcenter, "VL65A." & [VL65A].[dataid] AS tbldataid, VL65A.dataid AS dataid, VL65A.TS, DMin("[TS]","[VL65A]","[TS] > #" & [TS] & "#") AS EndTS, DateDiff("s",[TS],EndTS) AS durationsec, Format(Int([durationsec]/86400)) & " " & Format([durationsec]/86400,"hh:nn:ss") AS duration, Format(TS,"mm/dd/yyyy") AS [Day], Switch(incycle=0,'Down',incycle=1,'Running') AS Status
FROM VL65A
WHERE (((VL65A.TS)>Date()-3) AND ((VL65A.incycle)=0))
UNION ALL
SELECT "VL68B" AS workcenter, "VL68B." & [VL68B].[dataid] AS tbldataid, VL68B.dataid AS dataid, VL68B.TS, DMin("[TS]","[VL68B]","[TS] > #" & [TS] & "#") AS EndTS, DateDiff("s",[TS],EndTS) AS durationsec, Format(Int([durationsec]/86400)) & " " & Format([durationsec]/86400,"hh:nn:ss") AS duration, Format(TS,"mm/dd/yyyy") AS [Day], Switch(incycle=0,'Down',incycle=1,'Running') AS Status
FROM VL68B
WHERE (((VL68B.TS)>Date()-3) AND ((VL68B.incycle)=0))
;
I ended up using VBA to solve per #Erik's comments:
It loops through each connection checks it, if connection is good it modifies a query and runs.
Dim cnn As ADODB.Connection
Dim canConnect As Boolean
Set cnn = New ADODB.Connection
Dim conctns As Variant
Dim conctn As Variant
conctns = Array("HX32", "VL65A", "VL68B")
For Each conctn In conctns
On Error GoTo sub_error
cnn.Open conctn
If cnn.State = adStateOpen Then
canConnect = True
strSQL = "SELECT '" & conctn & "' AS workcenter, '" & conctn & ".' & [" & conctn & "].[dataid] AS tbldataid, " & conctn & ".dataid AS dataid, " & conctn & ".TS, DMin('[TS]','[" & conctn & "]','[TS] > #' & [TS] & '#') AS EndTS, DateDiff('s',[TS],EndTS) AS durationsec, Format(Int([durationsec]/86400)) & ' ' & Format([durationsec]/86400,'hh:nn:ss') AS duration, Format(TS,'mm/dd/yyyy') AS [Day], Switch(incycle=0,'Down',incycle=1,'Running') AS Status FROM " & conctn & " WHERE (((" & conctn & ".TS)>Date()-3) AND ((" & conctn & ".incycle)=0));"
CurrentDb.QueryDefs("unionall").SQL = strSQL
DoCmd.OpenQuery "appendall", acViewNormal, acEdit
DoCmd.OpenQuery "splithours", acViewNormal, acEdit
MsgBox conctn & " updated: " & canConnect
cnn.Close
End If
sub_error:
MsgBox conctn & ": " & Error$
Resume sub_error_exit
sub_error_exit:
Next conctn

Syntax error in number using query expression in MS-Access

I got Syntax error in number using query expression? error while I run below code
CurrentDb.Execute "UPDATE StateBudget " & _
" Set S_ID='" & Me.cbState & "'" & _
", C_ID=" & Me.cbCategory & _
", Year='" & Me.cbYear & "'" & _
", 1=" & Me.Ctl1 & _
", 2=" & Me.Ctl2 & _
", 3=" & Me.Ctl3 & _
" WHERE S_ID = """ & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'") & """"
S_ID and Year are Text fields, C_ID and the rest 1,2,3 are Number fields.
If there anything I missed? I am a beginner in programming so...
Probably one of number Me.* fields is null, so SQL will have syntax error. Use Nz function for such kind arguments. For debugging create SQL in string variable before executing and dump content of this variable to Immediate window using Debug.Print. You will see the problem easily.
Dim strSQL
strSQL = "UPDATE StateBudget " & _
" Set S_ID='" & Me.cbState & "'" & _
", C_ID=" & Nz(Me.cbCategory, 0) & _
", Year='" & Me.cbYear & "'" & _
", 1=" & Nz(Me.Ctl1, 0) & _
", 2=" & Nz(Me.Ctl2, 0) & _
", 3=" & Nz(Me.Ctl3, 0) & _
" WHERE S_ID = """ & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'") & """"
Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError