Agree. Nulls are a source of multiple problems. What does not appear in the table definition, is that ALL fields have a default value.I haven't been following this thread and this may well be irrelevant to whatever you are discussing. However, you should avoid allowing nulls in bit fields in SQL Server tables linked to Access. These are often the cause of write conflict errors.
![]()
Write Conflict Errors
This article explores some of the causes of the 'dreaded' write conflict error and how to deal with those issues.www.isladogs.co.uk
Are you mixing up ControlSource with RowSource?The problem with the Combobox is that the Control Source should have been intPersonInCharge instead of intID.
SELECT intID, nvcSurname FROM dbo_tblPersonInCharge
... RowSourceI do not think so. It is the field where the combo selection is stored.Are you mixing up ControlSource with RowSource?
Bound to intPersonInCharge ... ControlSource
SELECT intID, nvcSurname FROM dbo_tblPersonInCharge
... RowSource
How does this show? Does an error message appear or is the control locked?I cannot change the content of the Combobox.
You read that the problem has been solved, right?How does this show? Does an error message appear or is the control locked?
Is the problem only related to the combobox?
If you add a textbox next to the combobox and bind it to intPersonInCharge as well, can you enter an ID value?
' ...
rst!numCommonExpensePercent = rst!numArea / CDec(222.22)
' ...
Dim strSQL As String
strSQL = "UPDATE dbo_tblUnit SET numCommonExpensePercent = numArea / 222.22 " & _
"WHERE intBuildingID = " & Me.intBuildingID & ";"
CurrentDb.Execute strSQL, dbFailOnError
Yes, same errorDo you get the same error if you try:
Code:' ... rst!numCommonExpensePercent = rst!numArea / CDec(222.22) ' ...
Works fine. I guess because you deal with the SQL Server directly with little Access interventionOr you can avoid the recordset altogether:
Code:Dim strSQL As String strSQL = "UPDATE dbo_tblUnit SET numCommonExpensePercent = numArea / 222.22 " & _ "WHERE intBuildingID = " & Me.intBuildingID & ";" CurrentDb.Execute strSQL, dbFailOnError
I have usedCheck you haven't got ARITHABORT in SQL server set to on:
![]()
decimal and numeric (Transact-SQL) - SQL Server
Transact-SQL reference for the decimal and numeric data types. Decimal and numeric are synonyms for numeric data types that have a fixed precision and scale.learn.microsoft.com
SELECT [ARITHABORT] = CASE CAST(cfg.value AS INT) & 64 --bitwise operation on the 7th position
WHEN 0 THEN 'OFF'
ELSE 'ON' END
FROM sys.configurations cfg
WHERE name = 'user options'
SET AROTHABORT ON
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM dbo_tblUnit WHERE intBuildingID = " & Me.intBuildingID, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
If rst.BOF And rst.EOF Then
Else
rst.MoveFirst
Do While Not rst.EOF
rst!numCommonExpensePercent = rst!numArea / Me!numAreaTotal
rst.Update
rst.MoveNext
Loop
End If
Me.Requery
I see this all the time and always wonder why.3. When opening a recordset that does contain records (ie Not (.BOF And .EOF)), have you ever known it to open at anything other than the first record? Why .MoveFirst on open?
Similarly, you only need to test for .EOF when opening a recordset to see if it's empty.I see this all the time and always wonder why.![]()
Your thoughts are valid.Some thoughts:
1. Why use a recordset for this simple UPDATE? It's much more efficient to send a single UPDATE statement which will update all possible rows at once rather than have the overhead of creating a recordset object, downloading the data locally and performing row by row updates one at a time.
2. If you really must use a recordset, why use a ADODB recordset as opposed to a DAO recordset?
3. When opening a recordset that does contain records (ie Not (.BOF And .EOF)), have you ever known it to open at anything other than the first record? Why .MoveFirst on open?
DoCmd.SetWarnings True
DoCmd.RunSQL "UPDATE dbo_tblUnit SET numCommonExpensePercent = (numArea / " & Me!numAreaTotal & ") WHERE intBuildingID = " & Me.intBuildingID & ";"
DoCmd.SetWarningsFalse
Do While Not rst.EOF
rst!numCommonExpensePercent = Int(((rst!numArea / Me!numAreaTotal) + 0.005) * 100) / 100
rst.Update
rst.MoveNext
Loop
Yes, interesting as an academic exercise, since it's a problem you have no need of hitting.I came across the 222.22 problem during a debug session and the problem is "Why does it pose a problem
' ...
Dim TotalArea As Variant
' ...
TotalArea = 222.22
rst!numCommonExpensePercent = rst!numArea / TotalArea
' ...
Unless you late-bind, you need to ensure a reference is set to the ADODB library.Is there anything against an ADODB recordset and in favor of a DAO recordset?
Being extra verbose for sake of clarity is fine, however this is not a truly analagous example because specifying ASC does not cause any extra operation to be performed, whereas .MoveFirst is an unnecessary waste of computer cycles (granted, negligible to human perception!)By analogy, when I ORDER BY I always specify ASC and DESC
Can't you just use the same expression?Is there a way to achieve this with the UPDATE statement?
Dim strSQL As String
strSQL = "UPDATE dbo_tblUnit SET numCommonExpensePercent = Int(((numArea / " & Me!numAreaTotal & ") + 0.005) * 100) / 100 " & _
"WHERE intBuildingID = " & Me.intBuildingID & ";"
CurrentDb.Execute strSQL, dbFailOnError