Pasting data in ms access by criteria

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
on
Dear All;

Sorry again I'm confusing myself here on the criteria for pasting data in ms access table. I'm getting some sample data from internet by criteria, now I want also that to pasted according the reference form criteria in my contact table .

The form criteria to be used is Me.InvoiceNumber, this is on the same form where the click button is:

Private Sub CmdEmp_Click()
    Dim http As Object
    Dim JSON As Object
    Dim i As Integer
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim item As Object
    Set http = CreateObject("MSXML2.XMLHTTP")
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Contact")
    http.Open "GET", "http://jsonplaceholder.typicode.com/users/?id=" & Me.txtUserID, False
    http.send
    Set JSON = ParseJson(http.responseText)
    i = 2
    For Each item In JSON
        
        With rs
            .AddNew
            ![id] = item("id")
            ![firstName] = item("name")
            ![UserName] = item("username")
            ![email] = item("email")
            ![street] = item("address")("street")
            ![suite] = item("address")("suite")
            ![city] = item("address")("city")
            ![zipcode] = item("address")("zipcode")
            ![lat] = item("address")("geo")("lat")
            ![lng] = item("address")("geo")("lng")
            ![Phone] = item("phone")
            ![WebSite] = item("website")
            ![Company] = item("company")("name")
            ![catchPhrase] = item("company")("catchPhrase")
            ![bs] = item("company")("bs")
            .Update
        End With
        i = i + 1
    Next
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    Set JSON = Nothing
    Set http = Nothing

    MsgBox "Please note that your http run is complete check for new data in table called contact", vbExclamation, "Welcome to http hub"
    
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
I'm not sure what you mean. Looks like your code would insert a record into your Contact table. What does InvoiceNumber have to do with Contact?
Here is all I needed to do:

With rs
            .AddNew
            ![Id] = item("id")
            ![FirstName] = item("name")
            ![UserName] = item("username")
            ![EMail] = item("email")
            ![street] = item("address")("street")
            ![suite] = item("address")("suite")
            ![city] = item("address")("city")
            ![zipcode] = item("address")("zipcode")
            ![lat] = item("address")("geo")("lat")
            ![lng] = item("address")("geo")("lng")
            ![Phone] = item("phone")
            ![WebSite] = item("website")
            ![Company] = item("company")("name")
            ![catchPhrase] = item("company")("catchPhrase")
            ![bs] = item("company")("bs")
           [b] ![INVID] = Me.InvoiceID[/b]
            .Update

Open in new window


This work very well for me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial