B
Barry A&P
I scabbed together some code to automatically populate some form controls
based on what info it can find in the database, its goofy because some
records are not complete so i want to use what is usable.. My method may
be a little hacked so i would also appreciate any input on cleaning it up..
my table T_Installhistory has installation and removal data for a component,
the code finds the record for that component (By SNID) then Finds the Dmax
Removaldate i want everything else to refer to this record.. anyway my
issue is when the TSO and TSN boxes are populated on the form the numbers
have an extra zero on the end so i get 12340 instead of the correct 1234.0 i
tried changing the control to Fixed with 1 decimal but no luck.. the values
need to come from. the most recent removal date and matching SNID..
the math is RemovalParentTT - installParentTT (total Time) = TIS (time in
service) then installTSO + TIS = TSO and Install TSN + TIS = TSN (time
since New)
Where does my decimal point dissappear to ?
Maybe my use of strings is an issue
Here is my code
Private Sub SerialNumberIDCombo_AfterUpdate()
'Set all my variables
Dim RmvDate As String
Dim InstallID As String
Dim InstallTSN As String
Dim InstallTSO As String
Dim InstallparentTT As String
Dim RemovalParentTT As String
Dim TotalTIS As String
Dim ParentSNID As String
Dim Remarks As String 'string to fill remarks area on tag
Dim Reason As String
'Clear some stuff and fill what i can
Me!NSN = Me!SerialNumberIDCombo.Column(1)
Me!PartNumber = Me!SerialNumberIDCombo.Column(2)
Me!Description = Me!SerialNumberIDCombo.Column(3)
Me!SerialNumber = Me!SerialNumberIDCombo.Column(4)
Remarks = Me!SerialNumberIDCombo.Column(5)
Me!RemovedFrom = ""
Me!AtTT = ""
Me!TSO = ""
Me!TSN = ""
Me!TagDate = Date
'quit if there is no removal date
RmvDate = Nz(DMax("[RemovalDate]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo]), "#0#")
If RmvDate = "#0#" Then
MsgBox "No removal history found for this item..", , "No History
Available."
Me!SNNotes = Remarks
Exit Sub
End If
'show msg if the max removal date is less than the max install date
If DMax("[InstallDate]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo]) >= RmvDate Then
MsgBox "My Records show a Installation date posted after this removal
date. This tag may not have the most current data.", , "Warning!! Is
Component Installed?"
End If
'If the dates are good lets fill out some more data
InstallID = DLookup("[installID]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo] & " AND RemovalDate = #" & RmvDate & "#")
InstallTSN = Nz(DLookup("[installTSN]", "T_installhistory", "installID = " &
InstallID), "UNK")
InstallTSO = Nz(DLookup("[InstallTSO]", "T_installhistory", "installID = " &
InstallID), "UNK")
RemovalParentTT = Nz(DLookup("[RemovalParentTT]", "T_installhistory",
"installID = " & InstallID), "UNK")
InstallparentTT = Nz(DLookup("[InstallParentTT]", "T_installhistory",
"installID = " & InstallID), "UNK")
ParentSNID = Nz(DLookup("[ParentID]", "T_installhistory", "installID = " &
InstallID), "UNK")
Me!RemovedFrom = Nz(DLookup("[SerialNumber]", "T_Serialnumbers",
"SerialnumberID = " & ParentSNID), "UNK")
Me!AtTT = RemovalParentTT
'add a reason to our remarks string
If IsNull(DLookup("[ReasonForRemoval]", "T_installhistory", "installID =
" & InstallID)) Then
Remarks = "Removed: " & RmvDate & " " & Remarks
Else
Remarks = "Removed: " & RmvDate & " Reason: " &
DLookup("[ReasonForRemoval]", "T_installhistory", "installID = " & InstallID)
& " " & Remarks
End If
'We dont want to have bad data
If InstallparentTT = "UNK" Or RemovalParentTT = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
TotalTIS = RemovalParentTT - InstallparentTT
Me!AtTT = RemovalParentTT
'we also cant have a negative Time in service
If TotalTIS < 0 Then
Me!SNNotes = Remarks
Exit Sub
End If
If InstallTSO = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
Me!TSO = InstallTSO + TotalTIS
If InstallTSN = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
Me!TSN = InstallTSN + TotalTIS
'lets fineally fill that remarks box
Me!SNNotes = Remarks
End Sub
Thanks for your help
Barry
based on what info it can find in the database, its goofy because some
records are not complete so i want to use what is usable.. My method may
be a little hacked so i would also appreciate any input on cleaning it up..
my table T_Installhistory has installation and removal data for a component,
the code finds the record for that component (By SNID) then Finds the Dmax
Removaldate i want everything else to refer to this record.. anyway my
issue is when the TSO and TSN boxes are populated on the form the numbers
have an extra zero on the end so i get 12340 instead of the correct 1234.0 i
tried changing the control to Fixed with 1 decimal but no luck.. the values
need to come from. the most recent removal date and matching SNID..
the math is RemovalParentTT - installParentTT (total Time) = TIS (time in
service) then installTSO + TIS = TSO and Install TSN + TIS = TSN (time
since New)
Where does my decimal point dissappear to ?
Maybe my use of strings is an issue
Here is my code
Private Sub SerialNumberIDCombo_AfterUpdate()
'Set all my variables
Dim RmvDate As String
Dim InstallID As String
Dim InstallTSN As String
Dim InstallTSO As String
Dim InstallparentTT As String
Dim RemovalParentTT As String
Dim TotalTIS As String
Dim ParentSNID As String
Dim Remarks As String 'string to fill remarks area on tag
Dim Reason As String
'Clear some stuff and fill what i can
Me!NSN = Me!SerialNumberIDCombo.Column(1)
Me!PartNumber = Me!SerialNumberIDCombo.Column(2)
Me!Description = Me!SerialNumberIDCombo.Column(3)
Me!SerialNumber = Me!SerialNumberIDCombo.Column(4)
Remarks = Me!SerialNumberIDCombo.Column(5)
Me!RemovedFrom = ""
Me!AtTT = ""
Me!TSO = ""
Me!TSN = ""
Me!TagDate = Date
'quit if there is no removal date
RmvDate = Nz(DMax("[RemovalDate]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo]), "#0#")
If RmvDate = "#0#" Then
MsgBox "No removal history found for this item..", , "No History
Available."
Me!SNNotes = Remarks
Exit Sub
End If
'show msg if the max removal date is less than the max install date
If DMax("[InstallDate]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo]) >= RmvDate Then
MsgBox "My Records show a Installation date posted after this removal
date. This tag may not have the most current data.", , "Warning!! Is
Component Installed?"
End If
'If the dates are good lets fill out some more data
InstallID = DLookup("[installID]", "T_installhistory", "SerialNumberID = " &
Me![SerialNumberIDCombo] & " AND RemovalDate = #" & RmvDate & "#")
InstallTSN = Nz(DLookup("[installTSN]", "T_installhistory", "installID = " &
InstallID), "UNK")
InstallTSO = Nz(DLookup("[InstallTSO]", "T_installhistory", "installID = " &
InstallID), "UNK")
RemovalParentTT = Nz(DLookup("[RemovalParentTT]", "T_installhistory",
"installID = " & InstallID), "UNK")
InstallparentTT = Nz(DLookup("[InstallParentTT]", "T_installhistory",
"installID = " & InstallID), "UNK")
ParentSNID = Nz(DLookup("[ParentID]", "T_installhistory", "installID = " &
InstallID), "UNK")
Me!RemovedFrom = Nz(DLookup("[SerialNumber]", "T_Serialnumbers",
"SerialnumberID = " & ParentSNID), "UNK")
Me!AtTT = RemovalParentTT
'add a reason to our remarks string
If IsNull(DLookup("[ReasonForRemoval]", "T_installhistory", "installID =
" & InstallID)) Then
Remarks = "Removed: " & RmvDate & " " & Remarks
Else
Remarks = "Removed: " & RmvDate & " Reason: " &
DLookup("[ReasonForRemoval]", "T_installhistory", "installID = " & InstallID)
& " " & Remarks
End If
'We dont want to have bad data
If InstallparentTT = "UNK" Or RemovalParentTT = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
TotalTIS = RemovalParentTT - InstallparentTT
Me!AtTT = RemovalParentTT
'we also cant have a negative Time in service
If TotalTIS < 0 Then
Me!SNNotes = Remarks
Exit Sub
End If
If InstallTSO = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
Me!TSO = InstallTSO + TotalTIS
If InstallTSN = "UNK" Then
Me!SNNotes = Remarks
Exit Sub
End If
Me!TSN = InstallTSN + TotalTIS
'lets fineally fill that remarks box
Me!SNNotes = Remarks
End Sub
Thanks for your help
Barry