DLast - effort

  • Thread starter Thread starter siggy
  • Start date Start date
S

siggy

running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the last
number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...


siggy
 
In the DefaultValue Property try:

=DLast("[Ticket_number]","TICKET")+1

Notice the "=" sign.

You may want to use DMax instead, as the Last number isn't always the one
you expect. It often can be changed by sorting, whereas DMax is always the
highest number.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the last
number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...

Nope. DLast() is pretty nearly useless - it returns the last record
*IN DISK STORAGE ORDER*, and you can't control that order!

Instead, put a little bit of VBA code in the Afterupdate event of the
form control bound to Ticket_Number (I'll assume you've renamed it
txtTicket_Number):

Private Sub txtTicket_Number_AfterUpdate()
Me!txtTicket_Number.DefaultValue = "'" & Me!txtTicket_Number & "'"
End Sub

This will set the control's default value property to the entered text
string (needed even if the field is numeric) every time you update it.

John W. Vinson[MVP]
 
John Vinson said:
running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the
last number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...

Nope. DLast() is pretty nearly useless - it returns the last record
*IN DISK STORAGE ORDER*, and you can't control that order!

Instead, put a little bit of VBA code in the Afterupdate event of the
form control bound to Ticket_Number (I'll assume you've renamed it
txtTicket_Number):

Private Sub txtTicket_Number_AfterUpdate()
Me!txtTicket_Number.DefaultValue = "'" & Me!txtTicket_Number & "'"
End Sub

This will set the control's default value property to the entered text
string (needed even if the field is numeric) every time you update it.

Am I missing something, John, or wouldn't that want to be

Me!txtTicket_Number.DefaultValue = _
"'" & Me!txtTicket_Number + 1 & "'"

?
 
Am I missing something, John, or wouldn't that want to be

Me!txtTicket_Number.DefaultValue = _
"'" & Me!txtTicket_Number + 1 & "'"

?

Quite right, Dirk. Sorry 'bout that!

John W. Vinson[MVP]
 
the number sequence may not always be related to the maximum
( it is always related to the last record I entered )

one day I may be working with the set:
123456 to 123450
another day it may be 112345 to 112360

what I require is that after I enter the first number - say 112345
the next record defaults for 112346 .. and so on


** I will try the VBA code - that was suggested


siggy


Arvin Meyer said:
In the DefaultValue Property try:

=DLast("[Ticket_number]","TICKET")+1

Notice the "=" sign.

You may want to use DMax instead, as the Last number isn't always the one
you expect. It often can be changed by sorting, whereas DMax is always the
highest number.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

siggy said:
running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the last
number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...


siggy
 
the VBA code correctly increments the second entry...
but not subsequent entries

that is:
if I enter 12345 in my Ticket_Number field
the next new record has the correct 12346 value
- but the third record also has the value of 12346
( not 12347 - as if should )


siggy



Dirk Goldgar said:
John Vinson said:
running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the
last number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...

Nope. DLast() is pretty nearly useless - it returns the last record
*IN DISK STORAGE ORDER*, and you can't control that order!

Instead, put a little bit of VBA code in the Afterupdate event of the
form control bound to Ticket_Number (I'll assume you've renamed it
txtTicket_Number):

Private Sub txtTicket_Number_AfterUpdate()
Me!txtTicket_Number.DefaultValue = "'" & Me!txtTicket_Number & "'"
End Sub

This will set the control's default value property to the entered text
string (needed even if the field is numeric) every time you update it.

Am I missing something, John, or wouldn't that want to be

Me!txtTicket_Number.DefaultValue = _
"'" & Me!txtTicket_Number + 1 & "'"

?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
the VBA code correctly increments the second entry...
but not subsequent entries

that is:
if I enter 12345 in my Ticket_Number field
the next new record has the correct 12346 value
- but the third record also has the value of 12346
( not 12347 - as if should )


siggy

Please post the actual code you're using.

John W. Vinson[MVP]
 
siggy said:
the VBA code correctly increments the second entry...
but not subsequent entries

that is:
if I enter 12345 in my Ticket_Number field
the next new record has the correct 12346 value
- but the third record also has the value of 12346
( not 12347 - as if should )

Hmm. I suspect you should be using the form's AfterUpdate event, rather
than the control's AfterUpdate event.
 
Private Sub TicketNumber_AfterUpdate()
Me!TicketNumber.DefaultValue = "'" & Me!TicketNumber + 1 & "'"

End Sub


** as an "After Update" - Event Procedure
 
Hi,



DMax is the way to go, use the third argument to limit the range:


Nz(1+ DMax("ticketNumber", "tableName", "ticketNumber <=" &
MaxForTodayRange ) , MinForTodayRange)


Hoping it may help,
Vanderghast, Access MVP



siggy said:
the number sequence may not always be related to the maximum
( it is always related to the last record I entered )

one day I may be working with the set:
123456 to 123450
another day it may be 112345 to 112360

what I require is that after I enter the first number - say 112345
the next record defaults for 112346 .. and so on


** I will try the VBA code - that was suggested


siggy


Arvin Meyer said:
In the DefaultValue Property try:

=DLast("[Ticket_number]","TICKET")+1

Notice the "=" sign.

You may want to use DMax instead, as the Last number isn't always the one
you expect. It often can be changed by sorting, whereas DMax is always
the highest number.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

siggy said:
running Access 2000

I enter 20-30 records at a time each having an eight digit number,
these are often sequential, so I would like the default to be the last
number entered.... BUT so that I can still change the number

I was trying to use:
DLast("[Ticket_number]","TICKET")+1

just does not seem to work as I thought...


siggy
 

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