Results 1 to 2 of 2
  1. #1
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169

    while code

    I have a form set up that queries a table and then outputs to excel but having a little block with coding.

    i have

    private sub fljan11_click()
    docmd.openquery "fljan11"

    ****need some while the query is open perform this function*****

    I have the function portion as

    Set objXLApp = CreateObject("Excel.Application")
    Set objXLBook = objXLApp.Workbooks.Open("path for .xls")


    objXLApp.Application.Visible = True

    With objXLBook.ActiveSheet

    Set r = .usedRange
    i = r.Rows.Count + 1

    .cells(i + 1, 1).value = me.pol
    .cells(i + 1, 1).value = me.customer

    ***code for excel goes on. I know the code is no issue for the excel output it is just getting a dowhile that query is open or running write to the excel.
    thanks....

  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,521
    I assume you mean you want to loop through the query's records. Here's my template code for a loop:

    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT ..."
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
    
        rs.MoveNext
      Loop
    
      set rs = nothing
      set db = nothing
    You'd use your query in the source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Need help with VBA code here
    By goodguy in forum Programming
    Replies: 2
    Last Post: 09-09-2011, 06:26 AM
  2. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  3. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  4. Need code
    By Patience in forum Access
    Replies: 8
    Last Post: 07-01-2010, 07:26 AM
  5. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM

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