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

Autocopy and increasing by 1 for each record, keeping the input OK.

Status
Not open for further replies.

Ju

Technical User
Jul 4, 2000
61
FR
I'd like to autocopy the content of a field in a form and keep the &quot;format&quot; ok:<br>I have 000001 in my first record an I'd like to automatically have:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;000002 in the second,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;000003 in the third,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc...<br>for now I started to use:<br><br>Private Sub NoEnreg_AfterUpdate()<br><br>Me!NoEnreg.DefaultValue = Me!NoEnreg.Text + 1<br><br>End Sub<br>But It doesn't work...It increments the first time without keeping the zeros, then it keeps on &quot;autocopying&quot; the same.<br><br>Thanks.
 
try:<br><br>me!NoEnreg.DefaultValue = Right(&quot;00000&quot; & (me!NoEnreg.text + 1), 6)<br><br>This will keep the zeros at the beginning of the value. <p>-Chopper<br><a href=mailto: > </a><br><a href= > </a><br>
 
Well,<br>here is what I typed in my form code:<br>Private Sub NoEnreg_AfterUpdate()<br>Me!NoEnreg.DefaultValue = Right(&quot;00000&quot; & (Me!NoEnreg.Text + 1), 6)<br>End Sub<br><br>and it doesn't keep the zeros and it still doesn't increment my number except the first time...<br><br>Any ideas?<br><br>Thanks.
 
You can keep the leading zeros by setting the field's Format property to 000000.&nbsp;&nbsp;This will display a six-digit number, zero-filled.&nbsp;&nbsp;If you need more than six digits, simply add more zeros to the property.&nbsp;&nbsp;If you only want to display the number in this format, do this on the form.&nbsp;&nbsp;If you want to actually store the number in this format, do this in the underlying table as well.&nbsp;&nbsp;For more info, check out the on-line help topic&nbsp;&nbsp;&quot;Format Property — Number and Currency Data Types&quot;.<br><br>You can increment the number in the field by using<br>&nbsp;&nbsp;=Dlast(&quot;YourFieldName&quot;,&quot;YourTableName&quot;)+1<br>in the default value of the field.&nbsp;&nbsp;This needs to be done on the form, not the table.
 
Everything isn't really working...<br>Actually, the way it increments is quite strange, and it doesn't keep the zeros...strange. Here is what I have:<br>first&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;000002<br>then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;etc...<br>I don't really understand that.<br><br>By the way; a lot of people gave me the expression Dlast with a coma (,). I am under Access 2000 and it doesn't want a coma but a semi-colon(;).<br>So the expression is =Dlast(&quot;FieldName&quot;;&quot;TableName&quot;)+1<br><br>Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top