+ Reply to Thread
Results 1 to 4 of 4

VBA code for pulling a sequential number from a text file dependent on a form entry.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    VBA code for pulling a sequential number from a text file dependent on a form entry.

    Ok, let me start off with I am an accountant and not a programmer so please hold my hand here, I'm a novice at best. I have a client that for the moment wants to automate a lot of their bookkeeping but isn't quite ready to leave Excel for an accounting suite.

    What I have: A form for quotes/purchase orders stored on a network folder.

    What I am trying to accomplish: When an employee clicks on the Purchase Order option and submits the form a sequential purchase order number is auto populated, lets say in cell E8. The employee then saves the file as a pdf, so the excel file is just the template.

    What I have so far: I have a working form, I tried to put a text file on a network directory under several folders J:\stuff\stuff\stuff\POnumber.txt

    I found some code cruising the forums that VBA does just not like. It was for making a macro and then I was going to run an if statement for the macro, and it just turned out being a mess.

    I figured at this point it would be better just to start over. I have tried searching for what I need, but I either can't get my head around it or it just doesn't seem to apply to my situation.

    Very appreciative for any and all help

    Grant

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA code for pulling a sequential number from a text file dependent on a form entry.

    untested but maybe:
    Sub Macro_1
    dim fs, fil, num
    set fs = createobject("Scripting.filesystemobject")
    set fil = fs.opentextfile("J:\stuff\stuff\stuff\POnumber.txt",2)
    num = fil.readline
    fil.writeline num+1
    Range("E8") = num
    end sub

  3. #3
    Registered User
    Join Date
    10-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: VBA code for pulling a sequential number from a text file dependent on a form entry.

    Sorry it has taken awhile to get back to you. I get a run time error 54 - bad file mode error and when I debug it highlights on the num=fil.readline line. Any ideas?

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA code for pulling a sequential number from a text file dependent on a form entry.

    Sub Macro_1()
    Dim fs, fil, num
    Set fs = CreateObject("Scripting.filesystemobject")
    Set fil = fs.opentextfile("E:\test3.txt", 1)
    num = fil.readline
    Set fil = fs.opentextfile("E:\test3.txt", 2)
    fil.writeline num + 1
    End Sub
    ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-07-2013, 09:08 AM
  2. Need macro that will update a sequential number field each time I print a form
    By eradline in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2012, 05:55 PM
  3. Replies: 4
    Last Post: 11-25-2009, 07:05 PM
  4. Using a text file to hold sequential numbers
    By spanker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-15-2009, 03:58 PM
  5. Printing a form with a sequential number
    By dalah in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2006, 01:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1