My Assistant
![]() ![]() |
|
|
Dec 17 2008, 12:27 PM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 69 |
Private Sub txtStationRunNumber_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset Dim strStationRunNumber As String Dim strCriteria As String Dim lngBookmark As Long I am using the following code to check if a value has already been entered. If so, I want to clear only that field. However, I get the error mismatch message and two fields get cleared out. All help is appreciated. If Nz(Me.StationRunNumber, "") <> "" Then strStationRunNumber = Me.StationRunNumber Set rst = Me.RecordsetClone strCriteria = "[StationRunNumber]='" & strStationRunNumber & "'" lngBookmark = Nz(DLookup("StationRunNumber", "tblIncidents", strCriteria), 0) If lngBookmark > 0 Then Me.Undo MsgBox "The Station Run Number of " & strStationRunNumber & " already exists in the database." & vbCrLf & vbCrLf & _ "Please re-enter the Station Run Number", vbInformation, "Duplicate Station Run Number " & strStationRunNumber End If rst.Close Set rst = Nothing End If End Sub |
|
|
|
Dec 17 2008, 12:29 PM
Post
#2
|
|
|
UtterAccess Enthusiast Posts: 69 |
I should also mention that the StationRunNumber is a numeric field.
|
|
|
|
Dec 17 2008, 12:53 PM
Post
#3
|
|
|
Utter A-fishin'-ado Posts: 17,723 From: Cincinnati, Ohio, USA . . . ><((((°> |
If StationRunNumber is a numeric then it should not be enclosed in single quotes here:
strCriteria = "[StationRunNumber]='" & strStationRunNumber & "'" |
|
|
|
Dec 17 2008, 03:32 PM
Post
#4
|
|
|
UtterAccess Enthusiast Posts: 69 |
Just so I understand, it should be like this?
strCriteria = "['StationRunNumber']='" & strStationRunNumber & "'" Is that the only place I need to change it? THanks. |
|
|
|
Dec 17 2008, 03:36 PM
Post
#5
|
|
|
Utter A-fishin'-ado Posts: 17,723 From: Cincinnati, Ohio, USA . . . ><((((°> |
No ... I said it should NOT be enclosed ...
strCriteria = "[StationRunNumber]=" & strStationRunNumber |
|
|
|
Dec 17 2008, 03:41 PM
Post
#6
|
|
|
UtterAccess Enthusiast Posts: 69 |
Thank you for your help.
|
|
|
|
Dec 17 2008, 03:47 PM
Post
#7
|
|
|
Utter A-fishin'-ado Posts: 17,723 From: Cincinnati, Ohio, USA . . . ><((((°> |
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 19th June 2013 - 12:50 AM |