Results 1 to 11 of 11
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Adding data to table, with VBA y u no easy!?

    I have a table (tbl_21_only_temp) full of data. This table has 8 columns. The first 7 are already populated, however the 8th column is blank..I need to fill in this column on the current record selected. I really don't know how to acheive this using vba. I can tell you that Data will always be the same.. it will be "WebFrm.Document.all.Item("result").innerText"

    Code:
    Sub Looper()
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qry_21_days_only_Temp"
    DoCmd.SetWarnings True
    
    
    Dim r As DAO.Recordset
      Set r = CurrentDb.OpenRecordset("Select * from tbl_21_only_temp") ' Query or Table records to loop thru
       'Check to see if the recordset actually contains rows
         If Not (r.EOF And r.BOF) Then
           r.MoveFirst
            Do Until r.EOF = True
    'Start code for each record to do here
    
    
                Call "fancyStuff"
           
                ''''HERE IS WHERE I NEED TO ADD THE DATA FROM "fancystuff" to the 8th column of the current record set. 
           
    'End code for each record here
            'Move to the next record. Don't ever forget to do this.
            r.MoveNext
        Loop
    Else
        MsgBox "There are not records in the recordset."
    End If
    
    
    MsgBox "Reached end of process"
    
    
    r.Close
    Set r = Nothing
    End Sub
    Columns on this table

    Client Number
    CLient Name
    InstallStatus
    ProjType
    Install Completion Date
    Software Name
    Vendor name


    & the one I need to fill out is "URL Created"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    What is "fancystuff" - a function or code you haven't built yet?

    Maybe simply:

    r![URL Created] = fancystuff()

    Or maybe just an UPDATE sql instead of opening and looping a recordset.

    CurrentDb.Execute "UPDATE tbl_21_only_temp SET [URL Created]='" & fancystuff() & "'"
    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
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I'll give this a shot today. Fancy stuff is a pretty elaborate IE navigation piece that utilizes a URL generator.

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    So I am still having a hard time, I think it might be with how I am breaking it up.. Take a look at what "fancyStuff" is doing

    Code:
    Sub fancystuff()
    Dim WebFrm As InternetExplorer
    Dim Number, Name As String
    
    
    Set WebFrm = Login("http://theurlwenavigate", True)
    
    
    Call SleepIE(WebFrm)
    
    
     Number = DLookup("[Client number]", "tbl_21_only_temp")
    
     Name = DLookup("[Client Name]", "tbl_21_only_temp")
     
    WebFrm.Document.getelementbyID("name").Value = Number & " - " & Name ' enters acct# and name with " - "
    
    
    PauseApp 1
    
    
    WebFrm.Navigate "javascript:doSubmit(encode())"  ' this one works!
    
    
    PauseApp 1  'Pause for page load, JS does not display readystates so Sleep does not work here
    
    
    
    
    Debug.Print WebFrm.Document.all.Item("result").innerText ' This is the text from the result box This is what I need to add to the URLCreated column of the table.
    
    
    End Sub

    So there is fancy stuff... I really don't know what I'm doing wrong. I am fairly new to modifying records etc etc. Any help is appreciated.

  5. #5
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Alright I comnbines the two things... Maybe you can make sense of it.


    Code:
    Sub Looper()
    
    
    Dim WebFrm As InternetExplorer
    Dim Number, Name As String
    Dim r As DAO.Recordset
     
      Set r = CurrentDb.OpenRecordset("Select * from tbl_21_only_temp") ' Query or Table records to loop thru
         'Check to see if the recordset actually contains rows
         If Not (r.EOF And r.BOF) Then
           r.MoveFirst
            Do Until r.EOF = True
    'Start code for each record to do here
    
    
    
    Set WebFrm = Login("http:website", True)
      Call SleepIE(WebFrm)
        Number = DLookup("[Client number]", "tbl_21_only_temp")
        Name = DLookup("[Client Name]", "tbl_21_only_temp")
      
    WebFrm.Document.getelementbyID("name").Value = Number & " - " & Name ' enters acct# and name with " - "
       PauseApp 1
    
    
    WebFrm.Navigate "javascript:doSubmit(encode())"  ' this one works!
       PauseApp 1  'Pause for page load, JS does not display readystates so Sleep does not work here
    
    
    Debug.Print WebFrm.Document.all.Item("result").innerText ' This is the text from the result box (this is what I need added to the column)
           
    
    
    'End code for each record here
            'Move to the next record. Don't ever forget to do this.
             r.MoveNext
        Loop
    Else
        MsgBox "There are not records in the recordset."
    End If
    
    
    MsgBox "Reached end of process"
    
    
    r.Close
    Set r = Nothing
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I don't really see need for the recordset. Nothing in the recordset is used in the code. The DLookups don't have any filter criteria so they will just return the first value in the table in each loop. But why are the Dlookups needed when you have the recordset of the same data?

    What is it you are trying to do? Do you want the same value from web page populated into all records?
    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.

  7. #7
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I have a table with lets say 20 records.

    I want the loop to start with the first record set

    I want the ieautomation to fire for each record at the end of this process

    WebFrm.Document.all.Item("result").innerText is what I want to add to the URLCreated Column on the table for that record

    over and over again

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Okay, but that code as is will just save the same data to all records. The DLookups are useless. Instead, try:

    WebFrm.Document.getelementbyID("name").Value = r![Client Number] & " - " & r![Client Name] ' enters acct# and name with " - "
    ...
    r![URL Created] = WebFrm.Document.all.Item("result").innerText


    Might need to set the edit mode of recordset, so before the Do While loop: r.Edit
    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.

  9. #9
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Alright, it looks good, it is cycling thru the records correctly. However it is not writing to the column. I get an error "3020 - Update or CancelUpdate without Addnew or Edit." Any thoughts?


    Code:
    Sub Looper()
    'DoCmd.SetWarnings False
    'DoCmd.OpenQuery "qry_21_days_only_Temp"
    'DoCmd.SetWarnings True
    
    
    Dim WebFrm As InternetExplorer
    Dim Number, Name As String
    Dim r As DAO.Recordset
     
      Set r = CurrentDb.OpenRecordset("Select * from tbl_21_only_temp") ' Query or Table records to loop thru
         'Check to see if the recordset actually contains rows
         
         If Not (r.EOF And r.BOF) Then
           r.MoveFirst
           r.Edit
            Do Until r.EOF = True
    'Start code for each record to do here
    
    
    Set WebFrm = Login("httpwebsite", True)
    Call SleepIE(WebFrm)
       Number = DLookup("[Client number]", "tbl_21_only_temp")
       Name = DLookup("[Client Name]", "tbl_21_only_temp")
      
    WebFrm.Document.getelementbyID("name").Value = r![Client Number] & " - " & r![Client Name] ' enters acct# and name with " - "
       PauseApp 1
    WebFrm.Navigate "javascript:doSubmit(encode())"  ' this one works!
    PauseApp 1  'Pause for page load, JS does not display readystates so Sleep does not work here
    
    
    
    
     r![URLCreated] = WebFrm.Document.all.Item("result").innerText 'error 3020 here
     
     
    'End code for each record here
            'Move to the next record. Don't ever forget to do this.
            r.MoveNext
        Loop
    Else
        MsgBox "There are not records in the recordset."
    End If
    
    
    MsgBox "Reached end of process"
    
    
    r.Close
    Set r = Nothing
    End Sub
    I also removed the Dlookups, they were worthless

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Trial and error. The only time I've ever edited recordset is a RecordsetClone.

    Review http://msdn.microsoft.com/en-us/libr.../ff821175.aspx

    Maybe:
    r.Edit
    r![URLCreated] = WebFrm.Document.all.Item("result").innerText
    r.Update
    r.MoveNext
    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.

  11. #11
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Got it!

    Code:
    Sub Looper()
    'DoCmd.SetWarnings False
    'DoCmd.OpenQuery "qry_21_days_only_Temp"
    'DoCmd.SetWarnings True
    
    
    Dim WebFrm As InternetExplorer
    Dim Number, Name As String
    Dim r As DAO.Recordset
     
      Set r = CurrentDb.OpenRecordset("Select * from tbl_21_only_temp") ' Query or Table records to loop thru
         'Check to see if the recordset actually contains rows
         
         If Not (r.EOF And r.BOF) Then
           r.MoveFirst
           r.Edit
            Do Until r.EOF = True
    'Start code for each record to do here
    
    
    Set WebFrm = Login("http://website", True)
    Call SleepIE(WebFrm)
      
    WebFrm.Document.getelementbyID("name").Value = r![Client Number] & " - " & r![Client Name] ' enters acct# and name with " - "
       PauseApp 1
    WebFrm.Navigate "javascript:doSubmit(encode())"  ' this one works!
    PauseApp 1  'Pause for page load, JS does not display readystates so Sleep does not work here
    
    
    Debug.Print WebFrm.Document.all.Item("result").Value
     r.Edit
     r![URLCreated] = WebFrm.Document.all.Item("result").Value
     
     
    'End code for each record here
            'Move to the next record. Don't ever forget to do this.
            r.Update
            r.MoveNext
            
        Loop
    Else
        MsgBox "There are not records in the recordset."
    End If
    
    
    MsgBox "Reached end of process"
    
    
    r.Close
    Set r = Nothing
    End Sub
    It WAS editing the first record, but not the second.. I added another r.edit within the loop, then an r.update before the r.movenext. Works like a charm. Once again you saved me. Give me a paypal donate button or something.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-14-2013, 12:38 PM
  2. Adding data from linked table to existing table???
    By claysea in forum Import/Export Data
    Replies: 3
    Last Post: 02-21-2013, 12:23 PM
  3. Replies: 3
    Last Post: 12-19-2011, 11:18 AM
  4. Adding data to a table
    By Jbelle7435 in forum Programming
    Replies: 17
    Last Post: 06-13-2011, 07:30 AM
  5. Adding a table cannot enter data
    By tak4 in forum Queries
    Replies: 0
    Last Post: 02-03-2009, 10:04 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