Question : VBA Code

I am looking for VBA code to do the following...

If txtA = "Inspection Report" then look in tblA find the last entry starting with IRP
eg. IRP0001_R01_170710
then make txtB = IRP0002_R01_todaysdate in the same format as above

Thanks

Answer : VBA Code

You can use this function - you need to modify the DMAx command to use your own field name and table.

Function NextVal()
' assumes format is always like IRP0001_R01_170710
Dim lastval
Dim first As String
Dim second As String
Dim third As String
lastval = Nz(DMax("IDFieldname", "tblA", "left(IDfieldname,3) = 'IRP'"), "")    ' modify this line
If lastval = "" Then
MsgBox "No Previous Value"
NextVal = ""
Exit Function
End If
first = "IRP" & Format(Val(Mid(lastval, 4)) + 1, "0000") & "-"
second = Mid(lastval, 9, 4)
third = Format(Date, "DDMMYY")
NextVal = first & second & third
End Function
Random Solutions  
 
programming4us programming4us