473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

incrementing a field on a continuous form

Hi - I have a field called Sequence on a continuous subform. The Sequence field belongs to a table called Project_Draw. This table has many 'Draw' records for each 'Project' record. So then the subform is tied to the main form by Project_ID.

I want the Sequence field to automatically increment each time I add a new record. I can't use the autonumber as I need to start a new sequence for each new Project_ID.

I've tried putting a max([Sequence]) in the subform's footer and that gives me the max sequence used so far. Then on the Current Record event, I've tried referencing this and adding 1 to it and putting that result in the Sequence field. That works fine if I've come to the record for the first time, but if I'm entering one record after another, the max([Sequence]) field in the footer doesn't seem to refresh in time, so I don't get an incremental value. I've also tried requerying the max field, but again with no luck.

I'm sure there must be an easier way to do this, but I can't figure it out.

Thanks in advance for your help.

Bill
Oct 14 '09 #1

✓ answered by NeoPa

DMax() stands for Domain Max. It's a Domain Aggregate function. You can specify the domain (including the criteria) within which it is aggregating. Max() simply aggregates across the domain already specified. It's used in various different situations and always refers to that situation exclusively. On a form it refers to the Max found within a specified control (not field I believe) on that form. It can be referenced in a control formula, but I'm not sure it can be within the VBA.

I know you have a table :
Table=[Project_Draw]
Expand|Select|Wrap|Line Numbers
  1. Field       Type    Index
  2. Project_ID  Number  Composite PK
  3. Sequence    Number  Composite PK
  4. ...
I assume you also have a controls called [Project_ID] and [Sequence] on the form in your SubForm control. Read that last bit carefully. It is how sub-forms work. The main form has a SubForm control, within which is held a form. I suggest for your form's (that is the form within the SubForm control) AfterUpdate event some code similar to the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.     With Me
  3.         .Sequence.Default = DMax(Expr:="[Sequence]", _
  4.                                  Domain:="[Project_Draw]", _
  5.                                  Criteria:="[Project_ID]=" & .Project_ID) + 1
  6.     End With
  7. End Sub

3 4636
NeoPa
32,556 Expert Mod 16PB
Try using DMax() instead Bill. Let us know if you need more precise assistance (It sounds like you're pretty well up on the concepts actually).
Oct 15 '09 #2
Hey NeoPa and thanks. I'm pretty bad with syntax. I tried the dmax, but am not getting the syntax right.

The first argument is the field name, which I put in brackets as [Sequence]

The second argument is the domain, which I took to be the table. The table is called Project_Draws, but I don't know how to do the syntax for this.

The third argument is the condition. I thought it would have to be the maximum sequence where the Project_ID of the subform was equal to the Project_ID in the Project_Draws table. But again, I'm not sure how to write that.

Also, am curious why dmax might work where max wouldn't.

Thanks,
Bill
Oct 16 '09 #3
NeoPa
32,556 Expert Mod 16PB
DMax() stands for Domain Max. It's a Domain Aggregate function. You can specify the domain (including the criteria) within which it is aggregating. Max() simply aggregates across the domain already specified. It's used in various different situations and always refers to that situation exclusively. On a form it refers to the Max found within a specified control (not field I believe) on that form. It can be referenced in a control formula, but I'm not sure it can be within the VBA.

I know you have a table :
Table=[Project_Draw]
Expand|Select|Wrap|Line Numbers
  1. Field       Type    Index
  2. Project_ID  Number  Composite PK
  3. Sequence    Number  Composite PK
  4. ...
I assume you also have a controls called [Project_ID] and [Sequence] on the form in your SubForm control. Read that last bit carefully. It is how sub-forms work. The main form has a SubForm control, within which is held a form. I suggest for your form's (that is the form within the SubForm control) AfterUpdate event some code similar to the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.     With Me
  3.         .Sequence.Default = DMax(Expr:="[Sequence]", _
  4.                                  Domain:="[Project_Draw]", _
  5.                                  Criteria:="[Project_ID]=" & .Project_ID) + 1
  6.     End With
  7. End Sub
Oct 16 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
15
by: Paul T. Rong | last post by:
Hi everybody, This time a very very difficult case: I have a table "tblStudent", there are 50 students, I also made a form "frmStudent" based on "tblStudent", now if I don't want to show all...
2
by: ThompsonJessical | last post by:
I am trying to use a button with the vba coding for SendObject Function to email a specific report based on the value of another field of the current record. The form is a continuous form and...
5
by: James | last post by:
I have a Continuous form in Access 2000. The form contains a date field and the user has requested( demanded nicely) that they want the date field to be yellow if there is no data in the field....
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: Paul Glavey | last post by:
Hello anyone any idea how to do this. The problem I am having has to do with Continuous Forms. In the header of the form I have 4 Combo boxes. For now lets just work on one combo box. The combo...
4
by: Susan Bricker | last post by:
I have a form that displays record information in Continuous Record display (scrollable list). One of the fields in the record is an Integer value called "rcode" (reason code). But, I don't want...
1
by: asandiego | last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need. I hope someone can lead me to what I should do or just an idea to what can be done. What I'm...
1
by: MikiEns | last post by:
Hi all, Please excuse me if this is incorrect I am new to MS access and this Forum and appreciate any advice on posting. I would Like the Tab key on the key board to take the cursor down...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.