Results 1 to 13 of 13
  1. #1
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    Place a 'calculated' value in each new record.

    Hi,



    I'm using Access 2010.

    An Order Entry table that users will be adding records to has an Order Number field that consists of the 4-digit year concatenated with a 4-digit sequential number.

    For example, the first Order entered this year would be Order Number 20110001, the second number - 20110002 etc.

    How do I get the next Order Number in the sequence to populate the Order Number Box whenever the users start entering a new order - and set the focus to the next field on the Order Entry Form?

    Thanks,

    Robeen

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi Paul,

    Thanks for the pointer - it was definitely helpful.

    What I still need is how to get my new [incremented] number into the Order Number field of the Order Entry Form when a new record is created.

    That's the part I'm having trouble with.

    There's a button on the form for 'New Order'. I want to put this whole 'procedure' into that button.

    I'd appreciate help with that!

    Thanks,

    Robeen

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Most common is probably either behind a "Save" button or in the after insert event of the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I know where to put the procedure - I just don't know what to put IN it - and how.


    I'm more used to putting VB or VBA behind a button. With Access 2010 - I go into the 'On Click' Event and it opens a Macro window and that's throwing me.

    Any tips on what I do once I'm IN that 'Macro window'? Do I create a function in a Module and then do a 'Run Code' in the Macro Window?

    That's the part I'm struggling with.

    Thanks!

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I haven't worked a lot with 2010, but you should be able to force it to VBA like this:

    http://www.baldyweb.com/FirstVBA.htm

    As to what goes there:

    Me.TextboxYouWantTheValueIn = YourCalculationHere
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi Paul,
    I was not able to force it to VBA the way you suggested [by typing in '[Event Procedure]' in the OnClick Event in the Properties Sheet. Access said it couldn't find the object 'Event Procedure' - and suggested typing in either a public function that was in a module or it said this:
    "Make sure that the function is either:
    Defined in the code for the form or report.
    - or -
    A public function that is in a module (not a class module)."
    So I'm guessing there should be a way to get into the code for the Form - but I still haven't figured out how.
    I'd appreciate any suggestions, educated guesses, wild conjecturing, clutching at straws . . .

    Any help will be appreciated!!

    Thanks!

  8. #8
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    About getting to the VBA code window in Access 2010.

    Hi Paul & others.
    I realize that I forgot to mention one important detail in my original question.
    I created a Web Database.
    You cannot use VBA in a web database in Access 2010. You have to use Macros.
    Here's the explanation I found in Help this morning:
    "Access Web Applications Access Web Applications are a new feature of Access 2010 with which you can publish an application to a Microsoft SharePoint server that is running Access Services. This enables other people to use your database via a standard Internet browser, instead of having to have Access installed on their computers. However, because VBA code is incompatible with the Web publishing feature, if you plan to publish your application as an Access Web Application, you must use only macros to perform programming tasks."
    Sorry I didn't mention that.

    I'm not sure how this will impact my progress or if I'll be able to do what I'm planning using macros.

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I should have thought of that. I knew there was no VBA allowed in Web databases. You should be able to do it with a macro, using the SetValue action I think. I don't have 2010 loaded here, but I know the macro window is a lot different, and more powerful.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I know I'm straying off topic a little but I'll ask anyway.

    My query [QueryDesigner] in Access 2010:
    SELECT Max([BoxNumber]) AS HighNumber
    FROM Master;
    DOES return the highest BoxNumber from the table.

    When I do this in VBA I get the first BoxNumber in the table - rather than the HIGHEST value:
    . . .
    Code:
     
    SQL = "SELECT Max(BoxNumber) AS BigBox FROM [Master] GROUP BY BoxNumber"
     
    With dbsA.OpenRecordset(SQL)
    If Not .EOF Then
    Box = !BigBox
    End If
    .Close
    End With
     
    MsgBox "In AddNextBoxNumber(). Highest Box Number = " & Box
    Any ideas what's going wrong?
    Thanks,
    Robeen

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure, you added the GROUP BY clause in the VBA code. That will get you the highest box number per box number; in other words you'll get every box number. Drop that clause and use the SQL from your test.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Somebody dope slap me.
    I had the SQL correct to begin with [just like from my access query designer] but my variable 'Box' was defined as 'Number' and I kept getting an 'Overflow'. Well - the largest number in my table is 2011003 - and I guess 'Number' wasn't able to get that.
    I changed it to double and it came back with the highest BoxNumber from the table.
    Thanks again Paul!
    Really appreciate your help.

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! You probably had it as Integer, which can't handle a number that big. You probably want Long Integer (Long in VBA), which can handle up to 2,147,483,647.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 21
    Last Post: 02-14-2011, 02:51 PM
  2. Rounding up decimal place
    By swagger18 in forum Programming
    Replies: 4
    Last Post: 01-28-2011, 08:29 AM
  3. Replies: 3
    Last Post: 09-21-2010, 11:25 PM
  4. score and place query
    By ymds in forum Queries
    Replies: 1
    Last Post: 06-10-2010, 06:07 PM
  5. Replies: 1
    Last Post: 05-21-2009, 08:13 AM

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