ProgNo can be a Number datatype. ProjNo is better left as Text.
I've tried picking what I think I need from your code below and inserting
it
in my database with some slight modifications, but no luck so far. I see
in
your code below, you've included apostrophes on either side of &
Me.txtProjNo &. What's the reason for this?
Ivor
Search criteria for a Text field (such as in a DMax() criteria
argument) must be delimited by either ' or " quotemarks; Date/Time
fields must be delimited by #; Number fields don't use any delimiter.
If ProgNo is numeric, your expression can be two function calls
simpler. I realized I left out a very critical + 1 - SORRY!
Private Sub Form_BeforeInsert(Cancel as Integer)
Me.txtProgNo = NZ(DMax("[ProgNo]", "qryProgresses", _
"[ProjNo] = '" & Me.txtProjNo & "'")) + 1
End Sub
To break down the logic here:
DMax("[ProgNo]", "qryProgresses", <criteria>)
will find the maximum value of ProgNo in the query qryProgresses for
the given criteria. If the criterion is
"[ProjNo] = '" & Me.txtProjNo & "'"
it will be evaluated to
[ProjNo] = 'A3123'
if txtProjNo contains A3123.
If there are no ProgNo values for this project - that is, this is the
first entry for the project - the DMax() function will return NULL.
Passing the DMax() function result to the function NZ will return 0 if
that is the case, otherwise it will return whatever number was found
by DMax.
The expression then adds 1 to that result (giving 1 for the first
entry, or 31 if there are already 30 entries) and put that incremented
value into the textbox txtProgNo.
John W. Vinson[MVP]