Auto entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i have a piece of code which i want to automatically use to change a value
of a field once the button has pressed. the code goes to the necxt record
and is supposed to automatically fill an entry with a number.

here is the code


DoCmd.GoToRecord , , acNewRec


newDocID = DMax("[Document ID]", "[Tbl_Documents]",
"[Tbl_Documents].[Project] = Frm_Main.Project & ''") + 1
Me.[Document ID] = newDocID

The only outcome is the message "You cancelled the previous operation" but i
cant see why if the code is following through line by line, it should go to a
new record then ammend the document id accordingly.
 
My first thought is that your trying to populate the current record that your
on (which may be your newly added record), not another new record. Comment
out the line that goes to a new record. See if that helps.

SteveD
 
Ive commented out the new record line and Im still getting the same error.
There is no record navigation and the only previous statement is a variable
declaration.
--
Thank you




SteveD said:
My first thought is that your trying to populate the current record that your
on (which may be your newly added record), not another new record. Comment
out the line that goes to a new record. See if that helps.

SteveD


andrew3254 said:
hi,

i have a piece of code which i want to automatically use to change a value
of a field once the button has pressed. the code goes to the necxt record
and is supposed to automatically fill an entry with a number.

here is the code


DoCmd.GoToRecord , , acNewRec


newDocID = DMax("[Document ID]", "[Tbl_Documents]",
"[Tbl_Documents].[Project] = Frm_Main.Project & ''") + 1
Me.[Document ID] = newDocID

The only outcome is the message "You cancelled the previous operation" but i
cant see why if the code is following through line by line, it should go to a
new record then ammend the document id accordingly.
 
Andrew,

I'm looking at what your doing and I must ask a couple of questions.
1) please make sure the field, DocumentID, is NOT an autonumber field.
2) It looks like the DMax function is using the field your on as a criteria,
this does not seem like what your after. I'm assuming that your after the
max number in this field, then +1 to set a new documentID so ....to get the
largest current number

'Max ID
newDocID = DMax("Document ID", "Tbl_Documents")
'New ID (Max + 1)
Me.[Document ID] = newDocID

Does this help?

SteveD


andrew3254 said:
Ive commented out the new record line and Im still getting the same error.
There is no record navigation and the only previous statement is a variable
declaration.
--
Thank you




SteveD said:
My first thought is that your trying to populate the current record that your
on (which may be your newly added record), not another new record. Comment
out the line that goes to a new record. See if that helps.

SteveD


andrew3254 said:
hi,

i have a piece of code which i want to automatically use to change a value
of a field once the button has pressed. the code goes to the necxt record
and is supposed to automatically fill an entry with a number.

here is the code


DoCmd.GoToRecord , , acNewRec


newDocID = DMax("[Document ID]", "[Tbl_Documents]",
"[Tbl_Documents].[Project] = Frm_Main.Project & ''") + 1
Me.[Document ID] = newDocID

The only outcome is the message "You cancelled the previous operation" but i
cant see why if the code is following through line by line, it should go to a
new record then ammend the document id accordingly.
 
Back
Top