R
Ray Todd Jr
I have a details form that contains the details of an individual with the
following fields:
firstname
lastname
Address1
Address2
City
State
Zip
I have code that when the Address1, Address2, City, State or Zip fields are
changed the original is copied to the Notes field to keep the original
address available for the user, should it be needed.
The code that I have works great, BUT what I am trying to prevent is when
the original address is either null or empty to not execute the 'archiving'
function.
The code as I currently have it:
Private Sub Form_Dirty(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Old_Address1 As String
Dim Old_Address2 As String
Dim Old_City As String
Dim Old_State As String
Dim Old_Zip As String
Dim strNotes As String
Dim strSQL As String
Dim DefID As Long
Dim NotesID As Long
DefID = Me.DefendantID
If IsNull(Me.Address1) Or Me.Address1 = "" Then
Else
Old_Address1 = Me.Address1
End If
If IsNull(Me.Address2) Or Me.Address2 = "" Then
Else
Old_Address2 = Me.Address2
End If
If IsNull(Me.City) Or Me.City = "" Then
Else
Old_City = Me.City
End If
If IsNull(Me.State) Or Me.State = "" Then
Else
Old_State = Me.State
End If
If IsNull(Me.Zip) Or Me.Zip = "" Then
Else
Old_Zip = Me.Zip
End If
Set db = CurrentDb()
Set rs = db.OpenRecordset("taDEFENDANTSNOTES", dbOpenDynaset,
dbAppendOnly)
rs.AddNew
rs!DefNoteDate = Now()
rs!DefNoteTime = Now()
rs!DefendantID = DefID
NotesID = rs!DefNotesID
rs.Update
rs.Close
If IsNull(Me.Address2) Or Me.Address2 = "" Then
strNotes = "The previous address was:" & Chr$(13) & Chr$(10)
strNotes = strNotes + Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address1 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_City & ", " & Old_State & " " & Old_Zip
Else
strNotes = "The previous address was:" & Chr$(13) & Chr$(10)
strNotes = strNotes + Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address1 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address2 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_City & ", " & Old_State & " " & Old_Zip
End If
strSQL = "Update taDEFENDANTSNOTES set DefNote= """ & strNotes & """
where DefNotesID=" & NotesID
db.Execute strSQL, dbFailOnError
Set db = Nothing
Set rs = Nothing
End Sub
Can someone please give me suggestions on how to better improve this code to
achieve what I am attempting to do?
Thanks,
Ray.
following fields:
firstname
lastname
Address1
Address2
City
State
Zip
I have code that when the Address1, Address2, City, State or Zip fields are
changed the original is copied to the Notes field to keep the original
address available for the user, should it be needed.
The code that I have works great, BUT what I am trying to prevent is when
the original address is either null or empty to not execute the 'archiving'
function.
The code as I currently have it:
Private Sub Form_Dirty(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Old_Address1 As String
Dim Old_Address2 As String
Dim Old_City As String
Dim Old_State As String
Dim Old_Zip As String
Dim strNotes As String
Dim strSQL As String
Dim DefID As Long
Dim NotesID As Long
DefID = Me.DefendantID
If IsNull(Me.Address1) Or Me.Address1 = "" Then
Else
Old_Address1 = Me.Address1
End If
If IsNull(Me.Address2) Or Me.Address2 = "" Then
Else
Old_Address2 = Me.Address2
End If
If IsNull(Me.City) Or Me.City = "" Then
Else
Old_City = Me.City
End If
If IsNull(Me.State) Or Me.State = "" Then
Else
Old_State = Me.State
End If
If IsNull(Me.Zip) Or Me.Zip = "" Then
Else
Old_Zip = Me.Zip
End If
Set db = CurrentDb()
Set rs = db.OpenRecordset("taDEFENDANTSNOTES", dbOpenDynaset,
dbAppendOnly)
rs.AddNew
rs!DefNoteDate = Now()
rs!DefNoteTime = Now()
rs!DefendantID = DefID
NotesID = rs!DefNotesID
rs.Update
rs.Close
If IsNull(Me.Address2) Or Me.Address2 = "" Then
strNotes = "The previous address was:" & Chr$(13) & Chr$(10)
strNotes = strNotes + Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address1 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_City & ", " & Old_State & " " & Old_Zip
Else
strNotes = "The previous address was:" & Chr$(13) & Chr$(10)
strNotes = strNotes + Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address1 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_Address2 & Chr$(13) & Chr$(10)
strNotes = strNotes + Old_City & ", " & Old_State & " " & Old_Zip
End If
strSQL = "Update taDEFENDANTSNOTES set DefNote= """ & strNotes & """
where DefNotesID=" & NotesID
db.Execute strSQL, dbFailOnError
Set db = Nothing
Set rs = Nothing
End Sub
Can someone please give me suggestions on how to better improve this code to
achieve what I am attempting to do?
Thanks,
Ray.