Results 1 to 4 of 4
  1. #1
    ssalem is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    39

    Calling sub routines No object

    I am not real familiar with VBA but am with programming. I have a function that I am calling from a MACRO to Format data that was imported from a text file and write it to a new file. The problem I am dealing with is that I want to call a subroutine of code that is called numerous times from the function. I seem to be just having problems with what I shoud use. I tried to create Public Functions and using a call command to call it. One of my subroutines is to loop through the file locating a paticular record and then returning to the original function. The problem I have is when I go to the called Function it does not recognize my recordset. It says I have no Object Defined. Here is just a snip it from my code. I tried to handle this like an error code by just putting routines at the end, using a goto and then exiting the function after my loop was complete but I got an error that there was no "Error". Please point me in the right direction of what I should be using here. I simply just want to call a subroutine so I don't have to write the code over and over. This is just a small snipit of my code...but gets the logic across I am trying to accomplish.

    Public Function ImportFormat()

    Dim db as dao.database
    dim rs1 as dao.recordset

    set db as currentdb()
    set rs1 as db.openrecordset("Import")

    Do until rs1.eof

    Select Case rs1!fld1
    Case Is = "B1"
    mcount2 = mcount2 + 1
    Call Pieces1
    b3pi = rs1!fld1
    Call Postage1
    b3po = rs1!fld1
    Case Is = "B2"
    mcount2 = mcount2 + 1
    Call Pieces1
    b4pi = rs1!fld1
    Call Postage1
    b4po = rs1!fld1
    Case Is = "B3 "
    mcount2 = mcount2 + 1
    Call Pieces1
    b7pi = rs1!fld1
    Call Postage1
    b7po = rs1!fld1
    End Select

    Loop

    End Function

    Public Function Pieces1()


    Do Until rs1!fld1 = "No. of Pieces"
    rs1.MoveNext
    mcount = mcount + 1
    Loop
    Return
    End Function

    Public Function Postage1()
    Do Until rs1!fld1 = "Total Total Postage"
    rs1.MoveNext
    mcount3 = mcount3 + 1
    Loop
    Return
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You can pass recordset to procedure. Example from my project:

    _____________

    Public Sub Conversion(rs As ADODB.Recordset)
    ...
    ____________

    ...
    Dim rsDataNew As ADODB.Recordset
    Set rsDataNew = New ADODB.Recordset
    rsDataNew.Open ...
    Call Conversion(rsDataNew)
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssalem is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    39
    I put Public Function Pieces (rs1 as dao.recordset) and I get an invalid arguement.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I never tried with DAO recordset. I just know what I posted as example works for me. Requires a VBA reference to Microsoft ActiveX Data Objects 2.8 Library
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Nesting sub routines in codebehind
    By rivereridanus in forum Access
    Replies: 3
    Last Post: 06-14-2012, 11:19 AM
  2. Replies: 1
    Last Post: 09-03-2011, 07:01 PM
  3. Replies: 3
    Last Post: 11-02-2010, 10:14 AM
  4. Replies: 1
    Last Post: 08-05-2010, 12:11 PM
  5. Replies: 0
    Last Post: 06-14-2010, 07:19 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