Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 6th, 2006, 01:19 AM
Authorized User
 
Join Date: May 2004
Location: , NH, USA.
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.......
Reply With Quote
  #2 (permalink)  
Old May 16th, 2006, 02:21 PM
Registered User
 
Join Date: Apr 2006
Location: Memphis, TN, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
            .MoveFirst
            ItmNum = .Fields("LineNumber")
        End With
    Else
        ItmNum = 0
    End If

    ItmNum = ItmNum + 1

    LineNumbering = ItmNum


John
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.