Assign Detail Number

K

Kevin

tblEstimates is a detail table for tblProjects, linked by
ProjectNumber. tblEstimates primary key is an AutoNumber,
but there is also a numeric field EstimateNumber which we
use elsewhere in our process.

There is an Estimates subform (fsubEstimates) embedded on
a main form (frmProjects). I would like the estimate
number (control txtEstimateNumber) to default to the next
available number, that is [Max(EstimateNumber) of this
Project] + 1.

Can anyone help?

TIA

Kevin
 
J

John Vinson

There is an Estimates subform (fsubEstimates) embedded on
a main form (frmProjects). I would like the estimate
number (control txtEstimateNumber) to default to the next
available number, that is [Max(EstimateNumber) of this
Project] + 1.

This is pretty easy. Use the BeforeInsert event of fsubEstimates with
code like:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtEstimateNumber = NZ(DMax("[EstimateNumber]", _
"[your-table-name]", "[Project] = " & Me!txtProject)) + 1
End Sub
 
K

Kevin Sprinkel

Thanks, John; your answers are always appreciated.

Your assessment, reminded me, though, of Inspector
Lestrade of the Sherlock Holmes mysteries. Being totally
baffled by the case himself, Holmes explained in full
detail the deductive logic which led him to the solution.

Lestrade's response (paraphrased): "How terribly easy!"

Thanks again.
Best regards.

Kevin Sprinkel
 
K

Kevin Sprinkel

John,

I've entered:

Me!txtEstimateNumber = Nz(DMax("[EstimateNumber]", _
"tblEstimates", "[JobNumber] = " _
& Me!txtJobNumberEstimates)) + 1

I've got an error message:

Run-time error '3075':
Syntax error (missing operator) in query
expression '[JobNumber]='.

Control references seem right. Do you understand what
I've done wrong?

Kevin Sprinkel
 
J

John Vinson

John,

I've entered:

Me!txtEstimateNumber = Nz(DMax("[EstimateNumber]", _
"tblEstimates", "[JobNumber] = " _
& Me!txtJobNumberEstimates)) + 1

I've got an error message:

Run-time error '3075':
Syntax error (missing operator) in query
expression '[JobNumber]='.

Control references seem right. Do you understand what
I've done wrong?

If JobNumber is a Text field you need the syntactically required
quotemarks (sorry, should have covered that eventuality!)

Me!txtEstimateNumber = Nz(DMax("[EstimateNumber]", _
"tblEstimates", "[JobNumber] = '" _
& Me!txtJobNumberEstimates & "'")) + 1

and sorry about the "simple" comment - I was once watching a master
woodworker assemble a tongue-in-groove joint and he said the same
thing. Simple... yeah, RIGHT! :-{)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Key for Detail Table 4
Calculated Form Control 5
Database for Project Stages 1
Linking 1
Form/Subform 5
Go To Control 1
Repost: Smart Hyperlink 2
Incomprehensible OpenArgs behavior 2

Top