Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 6th, 2006, 01:19 AM
Authorized User
Join Date: May 2004
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Line Item Numbers needed

Using a sub form to add line items to an order, want a line item number as a reference. The table for the subform has a field to store the value. Right now the line item is being entered manually for each line. How to assign this value automatically?

Hmmmm, maybe keep an invisible counter on the main form, start at 1, and increment every a record is saved in the subform? Then when new line is entered, get that value, add one and put result into field for line item, and update value on parent form? Would need to update Parent form only when sub form record is actually saved?

Yes, I think I may have just solved my own problem. Add a field to table for parent form that is LineItemCount.Put an invisible text box on parent that is bound to the LineItemCount. Will also need to find a way with handling deleting records in subform. Want to keep original line item numbers, so this should be OK, deleted records will leave gaps, but can still sort by LineItem number.

Thanks for listening.
I am still open to a known working method if you can share that with us.......
Old May 16th, 2006, 02:21 PM
Registered User
Join Date: Apr 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Here is a way I've handled this in the past with this Function routine.....

    Dim strSS As String
    Dim ItmNum As Integer
    Dim db As Database
    Dim recS As Recordset

    strSS = "SELECT [" & strTable & "].LineNumber " & _
            "FROM [" & strTable & "] " & _
            "ORDER BY [" & strTable & "].LineNumber DESC"

    Set db = CurrentDb()
    Set recS = db.OpenRecordset(strSS, dbOpenDynaset)

    If recS.RecordCount > 0 Then
        With recS
            ItmNum = .Fields("LineNumber")
        End With
        ItmNum = 0
    End If

    ItmNum = ItmNum + 1

    LineNumbering = ItmNum


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Reporting With Line Numbers ef1196 Pro Visual Basic 2005 10 December 12th, 2006 03:28 PM
I see no line numbers when viewing errors in brows kenn_rosie VB.NET 2002/2003 Basics 2 May 23rd, 2006 09:48 AM
[?] Line numbers in VBA Chantale Access VBA 6 November 3rd, 2004 07:17 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM
Find Out First Item of each item Group Jane SQL Language 1 November 22nd, 2003 12:42 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.