If you read this article
Microsoft Access Tables: Primary Key Tips and Techniques
http://www.fmsinc.com/free/newtips/primarykey.asp
you might want to rethink using text fields for the PK/FK fields. You could use autonumbers for the PK field and set an index on the field(s) that you don't want to have duplicates. And as far as I know, it is not accepted practice to change the PK field data.
In any case, I am a little confused by your code. First, "Type" is a reserved word in Access (and it is not very descriptive - "FixtureType" or "Fix_Type" or "TypeOfFix" would be better - IMO). Second, you have three different variables for the "Type'. And you might need to get the "Text" value property because the data hasn't been saved yet.
(The ".Value" property is the current value in the control, the ".Text" property is the uncommitted value being entered.)
Code:
Private Sub txtType_BeforeUpdate(Cancel As Integer)
Dim vType As String
If Len(Nz(Me.txtType, "")) < 1 Then
strText = "You must enter a fixtue type before moving on..." & vbCrLf & _
"Please try again"
strTitle = "FIXTURE TYPE MISSING"
Response = MsgBox(strText, vbCritical + vbRetryCancel, strTitle)
Cancel = True
Else
If Me.Type <> vtxtType Then
strText = "You are about to change the existing type " & UCase(vtxtType) & " to " & UCase(Me.Type) & vbCrLf & _
vbCrLf & _
"Do you wish to continue?"
strTitle = "CHANGE OF FIXTURE TYPE"
Response = MsgBox(strText, vbCritical + vbYesNo + vbDefaultButton2, strTitle)
If Response = vbYes Then
' check for duplication with an existing record
If DCount("[type]", "tbeFixtureTypeDetails", "[type]= '" & Me.Type & "'") > 0 Then
vmsgtxt = "This fixture type is already being used; please try again"
vmsgTitle = "DUPLICATE FIXTURE TYPE"
Response = MsgBox(vmsgtxt, vbCritical + vbRetryCancel, vmsgTitle)
Cancel = True
End If
' save the new entry
Me.Dirty = False
Else
Cancel = True
End If
End If
End If
End Sub
The control name is "txtType"
The public variable is named "vtxtType"
What is "Type"??