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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using incremented number to fill a field 1

Status
Not open for further replies.

lora

Programmer
Dec 1, 1999
43
US
i need to have a field on a number of reports which contains a number, eg. 870664; the reports will be set to print with a button click but i need to have the field incremented on each report.&nbsp;&nbsp;I am thinking possibly an open event which will look at a table with a single number,increment the number, and use that number to for the field on the report.&nbsp;&nbsp;With the same open even in each report i should be able to achieve the result i'm looking for...sound like this would work??? any ideas on how to code??<br><br>THANKS!!
 
I did something similar and here is the code for it.<br><br>this saves a number and increments it each time you need to.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyDB As Database, MySet As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MyDB = currentdb<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MySet = MyDB.OpenRecordset(&quot;Last-RA-Number&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Edit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Temp1 = MySet.Fields(&quot;Last_RA_Number&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Temp2 = Temp1 + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Fields(&quot;Last_RA_Number&quot;) = Temp2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;MySet.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;MyDB.Close <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
That sounds good I would use a variable that you set when you open the reports it gets the last report nuber with <br><br>&nbsp;recordset.findlast &quot;FieldName &gt; (starting Number)<br>&nbsp;variable = recordset!fieldname +1<br>recordset.edit<br>recordset!fieldname = variable<br>recordset.update<br><br>of course you have to set the the recordset variable and the database but something along those lines should work. I am also assuming that the first field is declared as a number<br><br>good luck
 
Set it up exactly as you planned.&nbsp;&nbsp;Assuming your table is called ReportSeq and the numeric column is also called ReportSeq then...<br>&nbsp;&nbsp;Add the ReportSeq table to your query (do not link it to your other tables), add ReportSeq column to your query grid... <br>&nbsp;&nbsp;Add this code to the report...<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.SetWarnings False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.RunSQL &quot;UPDATE ReportSeq SET ReportSeq.ReportSeq = [ReportSeq]+1&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.SetWarnings True<br></font><br> <p>Jim Conrad<br><a href=mailto:JimConrad@Consultant.com>JimConrad@Consultant.com</a><br><a href= > </a><br>
 
thanks for all of your responses!&nbsp;&nbsp;i went with the shortest number of lines (jims, and it worked great!) but i'll play with all of these just to get better at doing things with data...Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top