Results 1 to 3 of 3
  1. #1
    Lockrin is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    52

    Complex VBA Autonumber question

    Hello All, I have a somewhat complicated programming issue here. I know what I want to do but need some ideas on how to accomplish it. This will all be based on the OnClick event of a button on my form.



    Step 1: I want VBA to go to the last record in a query and add 1 to a field. This will be similar to an autonumber field but be different because it will reset at 1 when a new customer is being queried. So customer "A" will have 1, 2, 3..... and Customer "B" Will have 1, 2, 3.... and so on. (For reference this is the "Beam Number")

    Step 2: I want VBA to remember this number and when I print 3 separate reports it will use this as a field on my reports.

    Step 3: It will then loop back through and repeat these steps as many times as an unbound control on my form dictates.

    I already have the final part finished.

    Dim stDocNameRA As String
    Dim stDocNameDIF As String
    Dim stDocNameAD As String
    Dim intCounter As Byte
    'Calls out all Reports Needed
    stDocNameRA = "Record of Accomplishment"
    stDocNameDIF = "Dimesional Inspection Form"
    stDocNameAD = "Assembly Drawing"
    'Loop Reports Until number in QTY box is hit
    Do
    intCounter = intCounter + 1

    DoCmd.OpenReport stDocNameRA, acNormal
    DoCmd.OpenReport stDocNameDIF, acNormal
    DoCmd.OpenReport stDocNameAD, acNormal

    Loop Until intCounter = QTY


    Any help or ideas would be greatly appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Well, it seems like you already have your number, with intCounter. Make that a public variable instead of declaring it within this procedure. That will let you access it in code from the report, or you can create a public function that returns the value of the variable, and use it as the control source of a textbox:

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

  3. #3
    Lockrin is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    52
    I actually did the whole thing without using VBA. I set up an append query to add the necessary amount of records and added the three reports as subreports to a "master report" I then set the Cycle property to Current Record so that it collates them correctly.

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

Similar Threads

  1. Customizing the Autonumber field
    By wasim_sono in forum Access
    Replies: 3
    Last Post: 10-24-2014, 03:00 PM
  2. duplicate autonumber
    By rayc in forum Access
    Replies: 5
    Last Post: 06-19-2013, 07:50 AM
  3. Replies: 5
    Last Post: 01-22-2010, 08:21 AM
  4. AUTONUMBER
    By J A F F A in forum Database Design
    Replies: 1
    Last Post: 10-03-2007, 10:30 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