WHERE clause not finding specific record?

LisaOnMSN

Registered User.
Local time
Yesterday, 22:01
Joined
Jan 12, 2011
Messages
22
Humble assistance requested: below is sub that attempts to update the current record with a concatenated value. ALL records are being updated rather than the record specied in the WHERE clause. Person who designed this db used non-standard table names etc. so there are lots of spaces to contend with. If you could point out my error, I would be greatful.

Lisa
================================

Private Sub park_name_Change()
'Plan is to concatenate the facility code (derived from the park information in this combo box)
'with the record number to create the project number value. Sample: McCollum Park is facility
'code MC. The record number, which is automatically generated, is added with a hyphen to create
' MC-3313 as a project number.

On Error GoTo ErrorHandler
Dim strSQL As String ' store the SQL string used to update the current record
Dim strFilter As String ' store the lookup statement here for the Dlookup
Dim strFacilityCode As String ' Store the facility found by looking up the park name in the
' park_names_primary table
Dim strMyProjectNumber As String ' Store the newly concatenated value to create a project number

'If the record number got properly generated, it should be greater than 0 at this point...
If (Record_Number.Value > 0) Then
strFacilityCode = DLookup("[Fac Code]", "[park_names_primary]", "[PARK_NAME]=" & "'" & park_name.Value & "'")
Call MsgBox("strFacilityCode is: " & strFacilityCode)
strProjectNumber = strFacilityCode & "-" & Record_Number.Value
End If 'Then take the value from the park_name
'field and concatenate it to the record_number field with a hyphen.

strSQL = "UPDATE [Work Request] SET [Project Number Given] = " & "'" & strProjectNumber & "' " & _
"WHERE [Record_Number] = " & Record_Number.Value

Call DoCmd.SetWarnings(False)
Call DoCmd.RunSQL(strSQL)
Call DoCmd.SetWarnings(True)

CleanUpAndExit:
Exit Sub

ErrorHandler:
Call MsgBox("Error in park_name_Change occurred." & vbCrLf & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume CleanUpAndExit
End Sub
 
Thank you so much for your reply. Absolutely is a typo, which I have since corrected. However, I believe I assigned a value here -->


strProjectNumber = strFacilityCode & "-" & Record_Number.Value


<-- in the "If" block immediately after the call to the MsgBox. It does the update but updates ALL records rather than the record with the specified Record_Number from the WHERE clause.

Are there any other items I am doing incorrectly?
 
Last edited:
Someone pointed out to me that all I needed to do was ASSIGN the concatenated value to the underlying field, since only the current record is at issue - there's no need for all the effort to create a SQL clause. So I changed it to a simple assignment and it worked immediately. Thank you for getting me started on a solution path.

Lisa
 

Users who are viewing this thread

Back
Top Bottom