Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940

    Cheers.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  2. #17
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Any idea why it's not compatible with version 2007? This is the code:

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub btnRequest_Click()
    
        If IsNull(Me.RegistrationNumber) Then
            MsgBox "Missing registration number"
            Exit Sub
        End If
    
        Dim strUrl As String
        Dim strApiKey As String
        Dim objRequest As Object
        Dim objReqBody As Object
        Dim strResponse As String
        
        'use a dictionary to avoid string manipulation
        Set objReqBody = CreateObject("Scripting.Dictionary")
        objReqBody.Add "registrationNumber", Me.RegistrationNumber
    
        'assign your variables
        strUrl = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles"
        strApiKey = "XXX"
        
        'instantiate http
        Set objRequest = CreateObject("MSXML2.XMLHTTP")
    
        'send http request
        With objRequest
            .Open "POST", strUrl, False
            .setRequestHeader "Content-Type", "application/json"
            .setRequestHeader "Accept", "application/json"
            .setRequestHeader "x-api-key", strApiKey
            
            'convert dictionary to JSON
            .send JsonConverter.ConvertToJson(objReqBody)
            
            'store response in a string variable
            strResponse = .responseText
            
            'visualize response in immediate window
            Debug.Print strResponse
        End With
    
        'convert string response to a dictionary
        Dim parsedResponse As Object
        Set parsedResponse = JsonConverter.ParseJson(strResponse)
        
        If parsedResponse("message") = "Forbidden" Then
            MsgBox "Bad api key"
        Else
            'populate your textboxes
            Me.txtMake = parsedResponse("make")
            Me.txtColour = parsedResponse("colour")
            Me.txtEngineCapacity = parsedResponse("engineCapacity")
            Me.txtFuelType = parsedResponse("fuelType")
            Me.txtYearOfManufacture = parsedResponse("yearOfManufacture")
            Me.txtFirstRegistered = parsedResponse("monthOfFirstRegistration")
            Me.txtmotStatus = parsedResponse("motStatus")
            Me.txtmotDueDate = parsedResponse("motExpiryDate")
            Me.txtTaxStatus = parsedResponse("taxStatus")
            Me.txtTaxDueDate = parsedResponse("taxDueDate")
            Me.txtDateLastV5Issued = parsedResponse("dateOfLastV5CIssued")
        End If
        
    End Sub
    Click image for larger version. 

Name:	form.jpg 
Views:	15 
Size:	63.4 KB 
ID:	50614

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Says I need 14, I am on 12.
    I have managed to get into the code now and copy and paste to a new db.
    I also have 2 keys would you believe from the DVLA.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #19
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    I'm glad you made it work, too bad I don't have that version to debug the issues.

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Oh I do not have it working yet.
    I was unable to import the form to a new DB. I am going to recreate it later.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importing data into table from a form
    By Jimbola in forum Access
    Replies: 15
    Last Post: 06-04-2018, 02:57 AM
  2. Replies: 9
    Last Post: 12-15-2017, 08:31 PM
  3. conditionally importing table data from sql
    By vinayak36 in forum Access
    Replies: 7
    Last Post: 07-21-2017, 07:21 AM
  4. Importing data from Pivot Table?
    By jstoler in forum Import/Export Data
    Replies: 22
    Last Post: 07-11-2013, 06:58 AM
  5. Importing excel data into table automatically
    By jwalker55 in forum Import/Export Data
    Replies: 2
    Last Post: 01-10-2012, 07:56 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