VB incremention previous control value

  • Thread starter Thread starter mulletteeth
  • Start date Start date
M

mulletteeth

Instead of using,

'******** Code Start **********
const cQuote="""" 'Thats two quotes
me!Control.DefaultValue = cQuote & me!Control.Value & cQuote
'******** Code End **********

to give me the exact same value, how can I modify this statement to
increment the value by 1?
 
Instead of using,

'******** Code Start **********
const cQuote="""" 'Thats two quotes
me!Control.DefaultValue = cQuote & me!Control.Value & cQuote
'******** Code End **********

to give me the exact same value, how can I modify this statement to
increment the value by 1?

If the field is numeric,

me!Control.DefaultValue = cQuote & NZ(me!Control.Value) + 1 & cQuote

The NZ will let the field start at 1 if the user blanks it out.

John W. Vinson[MVP]
 
Thank you for your help. This works ... to a degree. Actually it
works for every other record. For example if I type a 1 then a 2
appears in the next record, like I want. When I enter the next record
I do not type anything since a 2 is already in there. But when I go
to the 3rd record there is a 2 in the field again. I change it to a 3
which then inserts a 4 into the 4th record. and on and on.

I am new to Access and I hope I have my terminology straight. Please
keep in mind I am a newbie when responding.

Thanks again.
 
In what event did you put that code?

You need to ensure that it runs for every record, not just on a change or
update.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
I am using it 'before update' I get an error if I use it 'after
update'

How do I ensure it runs for every record, not just on a change or
update?
 
On second thought, I realized that you only do want the DefaultValue to
change when the actual value changes, so AfterUpdate should be the
appropriate event. What error do you get with it in the AfterUpdate event?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
My bad, Doug. No error message appears. The same thing happens
whether the event is AfterUpdate or BeforeUpdate.
 
BeforeUpdate (or AfterUpdate) event for the control, or for the form? It
should be the form's AfterUpdate event.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
Thank you. That did the trick.

I have one more semi-related question. Currently when I am typing
data into the last field (ProdNum) in a record and I hit enter the
cursor returns to the first field in the next record. I would like to
change this so the cursor returns to the same field (ProdNum) in the
next record.
 

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

Back
Top