Yollem Crumble
New member
- Local time
- Today, 15:22
- Joined
- Dec 11, 2022
- Messages
- 1
Hi - I am new to this site but have been using MS Access with a ton of VBA behind for many years. Usually I can solve most problems but recently came across one I need help with. I have a form drawing data from a table. It contains a field for town/suburb and a field for Post code (Zip Code) I use another table to check the post code against the town (and State). On the Town field I have an after update to do the check. The code is as follows:
Private Sub Town_Suburb_AfterUpdate()
Dim psta As String
Dim ploc As String
Dim ppc As String
Dim pss As String
Dim pcare As String
Dim ans As String
Dim ab As Boolean
DoCmd.RunCommand acCmdSaveRecord
Me.[Suburb] = UCase(Me.[Suburb])
If Me.[Country] <> "Australia" Then GoTo endprocess
If IsNull([State]) Or IsNull([Suburb]) Then
MsgBox ("a suburb or town and state must be present to check post code")
Else
psta = [State]
ploc = [Suburb]
pss = Trim(ploc) & Trim(psta)
If IsNull(DLookup("pcode", "pcbrief", "loc_sta = '" & [pss] & "'")) Then
MsgBox ("Suburb not recognised")
Else
ppc = DLookup("pcode", "pcbrief", "loc_sta = '" & [pss] & "'")
[Postcode] = ppc
If ppc = [Postcode] Then
pcare = DLookup("PCA", "PCArea", "postcode = '" & [ppc] & "'")
Me.[PCA] = pcare
End If
End If
End If
ans = Log_Change("suburb", [Suburb], [Member_Number]) ' save the change to a log table
endprocess:
DoCmd.RunCommand acCmdSaveRecord
End Sub
The issue is in the two docmd.runcommand accmdsaveRecord lines
Both trigger a Write Conflict - this record has been changed by another user .......
I have tried using the line: "if me.dirty then me.dirty = False" but with the same result.
To make things stranger, if I remove the saves it only fails on every second occasion. Prior to a few months ago, it worked for some years.
Does anyone have a suggestion?
Thanks in advance
Private Sub Town_Suburb_AfterUpdate()
Dim psta As String
Dim ploc As String
Dim ppc As String
Dim pss As String
Dim pcare As String
Dim ans As String
Dim ab As Boolean
DoCmd.RunCommand acCmdSaveRecord
Me.[Suburb] = UCase(Me.[Suburb])
If Me.[Country] <> "Australia" Then GoTo endprocess
If IsNull([State]) Or IsNull([Suburb]) Then
MsgBox ("a suburb or town and state must be present to check post code")
Else
psta = [State]
ploc = [Suburb]
pss = Trim(ploc) & Trim(psta)
If IsNull(DLookup("pcode", "pcbrief", "loc_sta = '" & [pss] & "'")) Then
MsgBox ("Suburb not recognised")
Else
ppc = DLookup("pcode", "pcbrief", "loc_sta = '" & [pss] & "'")
[Postcode] = ppc
If ppc = [Postcode] Then
pcare = DLookup("PCA", "PCArea", "postcode = '" & [ppc] & "'")
Me.[PCA] = pcare
End If
End If
End If
ans = Log_Change("suburb", [Suburb], [Member_Number]) ' save the change to a log table
endprocess:
DoCmd.RunCommand acCmdSaveRecord
End Sub
The issue is in the two docmd.runcommand accmdsaveRecord lines
Both trigger a Write Conflict - this record has been changed by another user .......
I have tried using the line: "if me.dirty then me.dirty = False" but with the same result.
To make things stranger, if I remove the saves it only fails on every second occasion. Prior to a few months ago, it worked for some years.
Does anyone have a suggestion?
Thanks in advance