Liz, it's probably best to look up the maximum used value directly in the
subform's table. This works regardless of how the subform is sorted or
filtered.
Dim strWhere As String
Dim intChar As Integer
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter a parent record first."
Else
strWhere = "[CaseNumber] = " & Me.Parent.[CaseNumber]
intChar = Asc(Nz(DMax("ID", "MyTable", strWhere), "@"))
Me.txtID.Value = Chr(intChar + 1)
End If
Note: If CaseNumber (the foreign key field) is a Text type field, you need
extra quotes:
strWhere = "[CaseNumber] = """ & Me.Parent.[CaseNumber] & """"
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Liz Malcolm said:
I've inherited a database that uses a main form for parents and a subform
for children. Each child subform has a case number from the parent main
form and a separate alpha identifier starting with A. I'm having a problem
incrementing the alpha identifier. I've tried setting the default value to
A and adding one with the following code called from the Before Insert event
of the subform.
Dim CurrentAlpha As String
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter a parent record first."
Else
CurrentAlpha = txtID.Value
CurrentAlpha = Chr$(Asc(CurrentAlpha) + 1)
txtID.Value = CurrentAlpha
End If
but I just keeping getting B for the succeeding identifiers. Can someone
help me?