A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

setting dynamic values to a field



 
 
Thread Tools Display Modes
  #1  
Old September 22nd, 2008, 06:31 PM posted to microsoft.public.access.forms
יניב מינקוב
external usenet poster
 
Posts: 2
Default setting dynamic values to a field

hi

A book table in a library contains the "book's number" and the "copy
number".

I want to set a default in the Books form, in which for new book
entries, after choosing the book number, the "Copy num" field will get
automatically the N+1 number (one after the last existing copy).

Can I?

Thanks, Yaniv
  #2  
Old September 22nd, 2008, 11:11 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default setting dynamic values to a field

On Mon, 22 Sep 2008 10:31:09 -0700 (PDT), ???? ??????
wrote:

hi

A book table in a library contains the "book's number" and the "copy
number".

I want to set a default in the Books form, in which for new book
entries, after choosing the book number, the "Copy num" field will get
automatically the N+1 number (one after the last existing copy).

Can I?

Thanks, Yaniv


Your best bet here may be to use the AfterUpdate event of the book number
control (because only then will you be able to identify the copy number). Try
code something like

Private Sub BookNum_AfterUpdate()
If Me.NewRecord Then ' only increment on new records
Me!CopyNum = NZ(DMax("[CopyNum]", "[BookTable]", _
"[BookNum] = " & Me!BookNum)) + 1
End If
End Sub

Adapt with your own field and tablenames of course.
--

John W. Vinson [MVP]
  #3  
Old September 25th, 2008, 09:01 AM posted to microsoft.public.access.forms
יניב מינקוב
external usenet poster
 
Posts: 2
Default setting dynamic values to a field

On Sep 23, 1:11*am, John W. Vinson
wrote:
On Mon, 22 Sep 2008 10:31:09 -0700 (PDT), ???? ??????
wrote:

hi


A book table in a library contains the "book's number" and the "copy
number".


I want to set a default in the Books form, in which for new book
entries, after choosing the book number, the "Copy num" field will get
automatically the N+1 number (one after the last existing copy).


Can I?


Thanks, Yaniv


Your best bet here may be to use the AfterUpdate event of the book number
control (because only then will you be able to identify the copy number). Try
code something like

Private Sub BookNum_AfterUpdate()
If Me.NewRecord Then ' only increment on new records
* *Me!CopyNum = NZ(DMax("[CopyNum]", "[BookTable]", _
* * * * * "[BookNum] = " & Me!BookNum)) + 1
End If
End Sub

Adapt with your own field and tablenames of course.
--

* * * * * * *John W. Vinson [MVP]


It is Working! thank you very much

Yaniv
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.