Does this break the normalization of tables??
I have the following tables:
tblLocation
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
tblAcq
AcqID
TrackingNumber
PONumber
AcqDate
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
etc..
tblInvoice
InvoiceID
TrackingNumber
SONumber
InvoiceDate
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
etc..
Now, I have these tables and when the user enters a valid LocationCode it populates the rest of the fields with the information that is available in tblLocations. I wanted to do this so that the user could change the Address/AttnTo if they needed, but does it break the normalization of my tables?
I am also going to lock the information in these fields once a TrackingNumber has been put in so that the information cannot be changed accidentally (or intentionally). I know I can do this with an OnCurrent event and that is not my issue.
Any thoughts on this?
Thanks!!
This is the code that I use to update the fields. I'm still working on the whole "Me.Undo" part, because I really only want to undo the change made to the LocationCode field, but when I try Me.LocationCode .Undo (which it allows) it doesn't perform any action.
[code=vb]
Private Sub LocationCode_Be foreUpdate(Canc el As Integer)
Dim db As DAO.Database 'CurrentDb()
Dim rs As DAO.Recordset 'Various recordsets.
Dim strSQL As String 'SQL Clause
Dim intStoreNum As Integer
Dim strLocCode, strLocName, strAttn, strAdd1, strAdd2, StrAdd3, strCity, strState, strZip, strPhone, strFax As String 'Address Clause
Set db = CurrentDb
strSQL = "SELECT tblLocations.Cu stomerID, tblLocations.Lo cationCode, tblLocations.St oreNumber, tblLocations.Lo cationName, " & _
"tblLocations.A ttentionTo, tblLocations.Ad dress1, tblLocations.Ad dress2, tblLocations.Ad dress3, tblLocations.Ci ty, " & _
"tblLocations.S tate, tblLocations.Zi p, tblLocations.Ph one, tblLocations.Fa x " & _
"FROM tblLocations " & _
"WHERE (((tblLocations .CustomerID)=" & Me.CustomerID & ") AND ((tblLocations. LocationCode) = " & """" & Me.LocationCode & """" & "));"
Set rs = db.OpenRecordse t(strSQL, dbOpenSnapshot)
With rs
If .RecordCount = 1 Then
'Store the values in the query to memory.
strLocCode = "" & !LocationCode & ""
intStoreNum = !StoreNumber
strLocName = "" & !LocationName & ""
strAttn = "" & !AttentionTo & ""
strAdd1 = "" & !Address1 & ""
strAdd2 = "" & !Address2 & ""
StrAdd3 = "" & !Address3 & ""
strCity = "" & !City & ""
strState = "" & !State & ""
strZip = "" & !Zip & ""
strPhone = "" & !Phone & ""
strFax = "" & !Fax & ""
'Set the text boxes to the values found in the query.
StoreNumber = intStoreNum
LocationName = strLocName
AttentionTo = strAttn
Address1 = strAdd1
Address2 = strAdd2
Address3 = StrAdd3
City = strCity
State = strState
Zip = strZip
Phone = strPhone
Fax = strFax
Else 'What happens if a record cannot be found
MsgBox "The previous address was saved since no record could be found for:" & vbCrLf & LocationCode, vbOKOnly + vbInformation
Me.Undo
End If
End With
rs.Close 'Close the recordset
End Sub
[/code]
I have the following tables:
tblLocation
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
tblAcq
AcqID
TrackingNumber
PONumber
AcqDate
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
etc..
tblInvoice
InvoiceID
TrackingNumber
SONumber
InvoiceDate
LocationID
LocationCode
AttnTo
Address1
Address2
Address3
City
State
Zip
Phone
etc..
Now, I have these tables and when the user enters a valid LocationCode it populates the rest of the fields with the information that is available in tblLocations. I wanted to do this so that the user could change the Address/AttnTo if they needed, but does it break the normalization of my tables?
I am also going to lock the information in these fields once a TrackingNumber has been put in so that the information cannot be changed accidentally (or intentionally). I know I can do this with an OnCurrent event and that is not my issue.
Any thoughts on this?
Thanks!!
This is the code that I use to update the fields. I'm still working on the whole "Me.Undo" part, because I really only want to undo the change made to the LocationCode field, but when I try Me.LocationCode .Undo (which it allows) it doesn't perform any action.
[code=vb]
Private Sub LocationCode_Be foreUpdate(Canc el As Integer)
Dim db As DAO.Database 'CurrentDb()
Dim rs As DAO.Recordset 'Various recordsets.
Dim strSQL As String 'SQL Clause
Dim intStoreNum As Integer
Dim strLocCode, strLocName, strAttn, strAdd1, strAdd2, StrAdd3, strCity, strState, strZip, strPhone, strFax As String 'Address Clause
Set db = CurrentDb
strSQL = "SELECT tblLocations.Cu stomerID, tblLocations.Lo cationCode, tblLocations.St oreNumber, tblLocations.Lo cationName, " & _
"tblLocations.A ttentionTo, tblLocations.Ad dress1, tblLocations.Ad dress2, tblLocations.Ad dress3, tblLocations.Ci ty, " & _
"tblLocations.S tate, tblLocations.Zi p, tblLocations.Ph one, tblLocations.Fa x " & _
"FROM tblLocations " & _
"WHERE (((tblLocations .CustomerID)=" & Me.CustomerID & ") AND ((tblLocations. LocationCode) = " & """" & Me.LocationCode & """" & "));"
Set rs = db.OpenRecordse t(strSQL, dbOpenSnapshot)
With rs
If .RecordCount = 1 Then
'Store the values in the query to memory.
strLocCode = "" & !LocationCode & ""
intStoreNum = !StoreNumber
strLocName = "" & !LocationName & ""
strAttn = "" & !AttentionTo & ""
strAdd1 = "" & !Address1 & ""
strAdd2 = "" & !Address2 & ""
StrAdd3 = "" & !Address3 & ""
strCity = "" & !City & ""
strState = "" & !State & ""
strZip = "" & !Zip & ""
strPhone = "" & !Phone & ""
strFax = "" & !Fax & ""
'Set the text boxes to the values found in the query.
StoreNumber = intStoreNum
LocationName = strLocName
AttentionTo = strAttn
Address1 = strAdd1
Address2 = strAdd2
Address3 = StrAdd3
City = strCity
State = strState
Zip = strZip
Phone = strPhone
Fax = strFax
Else 'What happens if a record cannot be found
MsgBox "The previous address was saved since no record could be found for:" & vbCrLf & LocationCode, vbOKOnly + vbInformation
Me.Undo
End If
End With
rs.Close 'Close the recordset
End Sub
[/code]
Comment