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
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