Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment a field in a form by 1

Status
Not open for further replies.

Grieve1

Programmer
Jun 11, 2008
33
GB
Hi Me again

I have a fom "Payment Certificate" with a field called [Paymentnumber]now I want to increment this field by 1 when 2 conditions occur that is when field [companyname]=[companyname] and field [contractname] =[contractname]I can get it to work for company name but not for both. I am using a "qryMaxVal", then using code to call it in a dlookup. e.g.
Private Sub Contract_Name_AfterUpdate()
If Me.NewRecord Then
Me.[Payment Number] = DLookup("[MaxValue]", "qryMaxVal", "[CompanyName]=""" & [CompanyName] & """") + 1
End If

End Sub
 
Why not use Dmax?

Dmax("PaymentNumber","Relevant Table or Query","[CompanyName]=""" & [CompanyName] & """ AND [ContractName=""" & [ContractName] & """")

It seems that you have several design flaws. You may wish to read [URL unfurl="true"]http://www.R937.com/Relational.html[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top