Results 1 to 9 of 9
  1. #1
    carstenhdk is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2010
    Location
    Denmark
    Posts
    42

    Question Add the number "1" to a value

    Hi there


    I have a value, which I would like to generate some function for

    [Teamnumber] + 1


    So, if the teamnumber is 55, the result will be 56. I plan to do this in the feild in a form shown in design view. I am using a danish version, but I think the feild in properties is called "control element source" - directly translated. Is that possible?




    /Carsten

  2. #2
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Why do you need to add 1? Is this for a new record? If so, you can just use an auto-id field. If it's for some other purpose on the same record in a different field then you can do something like this.
    Code:
    dim intID as Integer
    If IsNull(Me!Teamnumber) Then
        Exit Sub
    End If
     
    intID=Me!Teamnumber
    Me!MyField=intID + 1

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    if you will Like to create a Function you can copy this in a module and save this in your database:

    Option Compare Database
    Dim MyTeamNumber As Integer
    Dim MyIncrement As Integer

    Function Increment(MyTeamNumber, MyIncrement) As Integer
    If IsNull(MyTeamNumber) Then Exit Function
    Increment = MyTeamNumber + MyIncrement
    End Function


    The syntax to use this Function will be:
    Increment([Field To Add Number To],The Number To add)
    e.g. If I want to add 1 to Team Number:
    Increment([Team Number],1)

    This will be sufficent.

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    if your problem is solved mark the thread solved.

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    if your problem is solved mark the thread solved.

  6. #6
    carstenhdk is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2010
    Location
    Denmark
    Posts
    42
    Quote Originally Posted by Datagopherdan View Post
    Why do you need to add 1? Is this for a new record? If so, you can just use an auto-id field. If it's for some other purpose on the same record in a different field then you can do something like this.
    Code:
    dim intID as Integer
    If IsNull(Me!Teamnumber) Then
        Exit Sub
    End If
     
    intID=Me!Teamnumber
    Me!MyField=intID + 1

    I have a form where I make new students entries. The students are a part of a team, so the AutoID is not an option. I believe, that the function should find the biggest number in the column and add one to the number. Itīs kinda like the AutoID, but it will be the same number for the amount of students entered in that form.

  7. #7
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    So, you're saying that the students are assigned to a "Team". I have a database on my website that might be similar to what you're doing. Instead of teams though, it's setup as assigning students to companies. Theres no type of function to add 1 to each student though. I'm not really sure why you would need this. You would just setup a relationship between the unique identifier in the "Teams" table and the foreign key in the students table.

    Quote Originally Posted by carstenhdk View Post
    I have a form where I make new students entries. The students are a part of a team, so the AutoID is not an option. I believe, that the function should find the biggest number in the column and add one to the number. Itīs kinda like the AutoID, but it will be the same number for the amount of students entered in that form.

  8. #8
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    This is what I have done.

    I have used a simple form. It is continuous form. When ever you open the form the team number adds 1 to the previous number. Its the same for all the entries that you make in the form. When you close the form and reopen it again 1 is added to the last team number.

    e.g. When you open for the First time team number is 1. You enter 10 names in the form and for all of them the team number id 1. When you close the form and reopen it again the Team number is 11 and for all the entries that you make the TeamNumber is 11.

    see if this is what you required.

    attached a mdb file for your reference.

  9. #9
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    You can Hide the textbox in the form footer.

    Code used:

    Private Sub Form_Open(Cancel As Integer)
    Dim intNumber As Integer
    intNumber = IIf(IsNull(DMax("[TeamNumber]", "Table1")), 1, DMax("[TeamNumber]", "Table1") + 1)
    Me.Text8 = intNumber
    End Sub

    Private Sub StudentName_AfterUpdate()
    Me.TeamNumber = Me.Text8
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2010, 10:22 AM
  2. Replies: 21
    Last Post: 06-03-2009, 05:54 PM
  3. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  4. Replies: 2
    Last Post: 08-31-2006, 12:19 PM
  5. "Count" and "Countif" in Reports
    By JMantei in forum Reports
    Replies: 1
    Last Post: 06-20-2006, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums