setting dynamic values to a field

  • Thread starter יניב מינקוב
  • Start date
×

יניב מינקוב

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
 
J

John W. Vinson

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.
 
×

יניב מינקוב

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).
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.

It is Working! thank you very much

Yaniv
 

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

Top