Originally posted by ggtw
[CODE=vb]
'Inserted in code block below
Dim intLastID As Integer, strLastFileNum As String, strLastProperty As String, strLastFileType As String
Dim strLastMainFile Name As String, strLastSubFileN ame As String
intLastID = DLast("[File ID]", "ALL")
strLastFileNum = DLookup("[FILE NUMBER]", "ALL", "[File ID]=" & intLastID)
strLastProperty = Left$(strLastFi leNum, 2)
strLastFileType = Mid$(strLastFil eNum, 3, 2)
strLastMainFile Name = Mid$(strLastFil eNum, 6, 2)
strLastSubFileN ame = Right$(strLastF ileNum, 1)[/CODE]
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strFileNum As String
If Me.NewRecord Then 'is this a New Record
'All 4 Fields must contain values in order to generate FILE NUMBER
If Not IsNull(Me![PROPERTY]) And Not IsNull(Me![FILE TYPE]) And Not IsNull(Me![MAIN FILE NAME]) And Not IsNull(Me![SUB FILES NAME]) Then
strFileNum = Me![PROPERTY] & Me![FILE TYPE] & "-" & Me![MAIN FILE NAME] & Me![SUB FILES NAME] 'concatenate the 4 entries
Dim intLastID As Integer, strLastFileNum As String, strLastProperty As String, strLastFileType As String
Dim strLastMainFileName As String, strLastSubFileName As String
intLastID = DLast("[File ID]", "ALL")
strLastFileNum = DLookup("[FILE NUMBER]", "ALL", "[File ID]=" & intLastID)
strLastProperty = Left$(strLastFileNum, 2)
strLastFileType = Mid$(strLastFileNum, 3, 2)
strLastMainFileName = Mid$(strLastFileNum, 6, 2)
strLastSubFileName = Right$(strLastFileNum, 1) 'future processing here
'Write this value to the FILE NUMBER Field (Temporary)
Me![FILE NUMBER] = strFileNum
Else '1 or more Fields contain no value - cannot do!
Cancel = True
End If
Else
End If
End Sub
Comment