G
I am trying to implement form that allows a user to update data in
multiple records in a table based on criteria they enter in the form.
Because I want to allow some user interaction on a record level, and
provide some additional data validation, I'm trying to do it with code
instead of an update query. Unfortunately, it's not letting me update
the data: I'm getting an error saying the data is read only. The same
query statement, when run as straight SQL, will allow edits in the
datasheet view IF I use inconsistent updates (which is why I'm using
the dbinconsistent option for openrecordset). But it still won't
update via code. Following is the pertinant code:
Dim db As Database
Dim rs As Recordset
Dim NewString As String
Set db = CurrentDb
If Me.NewFilterRack > 0 Then ' We want to change filter racks
NewString = DLookup("[FilterBoxDescription]",
"lookupFilterBoxType", "[FilterBoxType] = " & Me.NewFilterRack)
Set rs = db.OpenRecordset("SELECT Units.JobID, Units.GroupID,
Units.Order, Units.Tag, Units.UnitID, Types.UnitType, Types.FilterBox,
Units.FilterTypeID, Units.PreFilterTypeID, Types2.FilterBox, " &
Me.NewFilterRack & " AS NewFilterRack " & _
"FROM (SELECT EquipmentTypes.UnitType, EquipmentTypes.UnitSize,
EquipmentTypes.FilterBox " & _
"FROM EquipmentTypes " & _
"WHERE ((EquipmentTypes.FilterBox)=" & Me.NewFilterRack & ")) AS
Types2 RIGHT JOIN (EquipmentTypes AS Types INNER JOIN FilterJobUnits AS
Units ON Types.UnitID = Units.UnitID) ON (Types2.UnitSize =
Types.UnitSize) AND (Types2.UnitType = Types.UnitType) " & _
"WHERE (((Units.JobID)=" & Me.JobID & ") AND ((Units.GroupID)=" &
Me.GroupID & ") AND ((Types.UnitType)=" & Me.Model & " OR " & Me.Model
& " = 0) AND ((Types.FilterBox)=" & Me.FilterRack & " OR " &
Me.FilterRack & " = 0) AND ((Units.FilterTypeID)=" & Me.FilterType & "
OR " & Me.FilterType & " = -1) AND ((Units.PreFilterTypeID)=" &
Me.PreFilter & " OR " & Me.PreFilter & " = -1)) " & _
"ORDER BY Units.Order;", , dbInconsistent)
With rs
If (.BOF And .EOF) Then Exit Sub
.MoveLast
.MoveFirst
Do Until .EOF
If IsNull(![Types2.FilterBox]) = False Then
.Edit
![Types.FilterBox] = ![Types2.FilterBox]
.Update
.MoveNext
Else
If MsgBox(NewString & " is not a valid filter rack for " &
![Units.Tag] & ". The filter rack for this unit will NOT be changed.
Click OK to continue, or Cancel to abort changing further units.",
vbOKCancel) = vbCancel Then Exit Sub
End If
Loop
Set rs = Nothing
End With
rs.Close
End If
Set rs = Nothing
Set db = Nothing
Any suggestions?
Thanks!
multiple records in a table based on criteria they enter in the form.
Because I want to allow some user interaction on a record level, and
provide some additional data validation, I'm trying to do it with code
instead of an update query. Unfortunately, it's not letting me update
the data: I'm getting an error saying the data is read only. The same
query statement, when run as straight SQL, will allow edits in the
datasheet view IF I use inconsistent updates (which is why I'm using
the dbinconsistent option for openrecordset). But it still won't
update via code. Following is the pertinant code:
Dim db As Database
Dim rs As Recordset
Dim NewString As String
Set db = CurrentDb
If Me.NewFilterRack > 0 Then ' We want to change filter racks
NewString = DLookup("[FilterBoxDescription]",
"lookupFilterBoxType", "[FilterBoxType] = " & Me.NewFilterRack)
Set rs = db.OpenRecordset("SELECT Units.JobID, Units.GroupID,
Units.Order, Units.Tag, Units.UnitID, Types.UnitType, Types.FilterBox,
Units.FilterTypeID, Units.PreFilterTypeID, Types2.FilterBox, " &
Me.NewFilterRack & " AS NewFilterRack " & _
"FROM (SELECT EquipmentTypes.UnitType, EquipmentTypes.UnitSize,
EquipmentTypes.FilterBox " & _
"FROM EquipmentTypes " & _
"WHERE ((EquipmentTypes.FilterBox)=" & Me.NewFilterRack & ")) AS
Types2 RIGHT JOIN (EquipmentTypes AS Types INNER JOIN FilterJobUnits AS
Units ON Types.UnitID = Units.UnitID) ON (Types2.UnitSize =
Types.UnitSize) AND (Types2.UnitType = Types.UnitType) " & _
"WHERE (((Units.JobID)=" & Me.JobID & ") AND ((Units.GroupID)=" &
Me.GroupID & ") AND ((Types.UnitType)=" & Me.Model & " OR " & Me.Model
& " = 0) AND ((Types.FilterBox)=" & Me.FilterRack & " OR " &
Me.FilterRack & " = 0) AND ((Units.FilterTypeID)=" & Me.FilterType & "
OR " & Me.FilterType & " = -1) AND ((Units.PreFilterTypeID)=" &
Me.PreFilter & " OR " & Me.PreFilter & " = -1)) " & _
"ORDER BY Units.Order;", , dbInconsistent)
With rs
If (.BOF And .EOF) Then Exit Sub
.MoveLast
.MoveFirst
Do Until .EOF
If IsNull(![Types2.FilterBox]) = False Then
.Edit
![Types.FilterBox] = ![Types2.FilterBox]
.Update
.MoveNext
Else
If MsgBox(NewString & " is not a valid filter rack for " &
![Units.Tag] & ". The filter rack for this unit will NOT be changed.
Click OK to continue, or Cancel to abort changing further units.",
vbOKCancel) = vbCancel Then Exit Sub
End If
Loop
Set rs = Nothing
End With
rs.Close
End If
Set rs = Nothing
Set db = Nothing
Any suggestions?
Thanks!