Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Recordset Data

    Hi Guy's this is a bit of a method issue i would imagine



    If i tick 6 check boxes (AddToRoute), this means I have 6 postcodes to add to route

    I am aware that because i have got my Shell command within the loop that it will open 6 x URL's

    1: I guess i need to move myURL Command after the loop ?

    2: How would i then add the looped postcodes to 1 x URL ?

    3: Because each postcode requires a forward slash after the 1st one and before the next one etc...... how would I loop forward slashes within the recordset loop ?

    Is this achievable ?

    Code:
    Dim myURL As String, OpenChrome As StringDim iQty As Integer
    Dim pc1 As String, pc2 As String, pc3 As String, pc4 As String, pc5 As String
    Dim rs As DAO.Recordset
    
    
    
    
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE AddToRoute = Yes")
    
    
    Do Until rs.EOF
    
    
        myURL = "https://www.google.co.uk/maps/dir/" & Replace(rs.Fields("PostCode"), " ", "")
        OpenChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
        Shell OpenChrome & myURL, vbMaximizedFocus
    
    
    rs.MoveNext
    Loop

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Concatenate the postcodes with a slash within the loop into a string variable. Then use that outside the loop.
    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

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi Guy's I have since tried this to add the forward slashes, also moved the URL command outside the loop, now only getting 1 post code when i have checked 6 in recordset ?

    I though that If i moved the URL outside of the loop would result in opening 1 x URL which is correct, just now need to rsPC string for all records checked ?

    Code:
    Dim myURL As String, OpenChrome As String, rsPC As StringDim iQty As Integer
    Dim pc1 As String, pc2 As String, pc3 As String, pc4 As String, pc5 As String
    Dim rs As DAO.Recordset
    
    
    
    
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE AddToRoute = Yes")
    
    
    Do Until rs.EOF
    
    
    rsPC = Replace(Replace(rs.Fields("PostCode"), " ", ""), rs.Fields("Postcode"), rs.Fields("PostCode") & "/")
    
    
    rs.MoveNext
    Loop
    
    
       ' myURL = "https://www.google.co.uk/maps/dir/" & Replace(Replace(rsPC, " ", ""), rsPC, rsPC & "/")
        myURL = "https://www.google.co.uk/maps/dir/" & rsPC
        
        OpenChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
        Shell OpenChrome & myURL, vbMaximizedFocus

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You are not concatenating the postcodes though.
    Walk through your code line by line with F8 and inspect the variables.
    Use debug.print to see what you actually have, not what you think you have.
    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

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi WGM, thank you, I know you have mentioned numerous times to use F8 and debug.print

    Can i please admit, I am unsure, added debug.Print on this code and F8 is doing nothing, I have tried highlighting the code and pressing F8 again doing nothing

    Code:
    Dim myURL As String, OpenChrome As String, rsPC As StringDim iQty As Integer
    Dim pc1 As String, pc2 As String, pc3 As String, pc4 As String, pc5 As String
    Dim rs As DAO.Recordset
    
    
    
    
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE AddToRoute = Yes")
    
    
    Do Until rs.EOF
    
    
    rsPC = Replace(Replace(rs.Fields("PostCode"), " ", ""), rs.Fields("Postcode"), rs.Fields("PostCode") & "/")
    Debug.Print
    rs.MoveNext
    Loop
    
    
       ' myURL = "https://www.google.co.uk/maps/dir/" & Replace(Replace(rsPC, " ", ""), rsPC, rsPC & "/")
        myURL = "https://www.google.co.uk/maps/dir/" & rsPC
        
        OpenChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
        Shell OpenChrome & myURL, vbMaximizedFocus

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You need to set a breakpoint, if not executing from the code window.
    Click in the column to the left of the code and a red dot should appear. Click again, or select from the menu 'remove breakpoints' to remove it.
    Once you have a breakpoint, I would put it on the Do until line, then the code will stop at that line in the code window.
    Now you press F8 to move to each line. At the same time, either hover over the variable/field to see it's contents, or add a debug.print variablename in a line of code.

    All debug.prints output to the immediate window (Ctrl + G)

    Now you are in control and can see where your code goes and what it produces, step by step.

    Look at the link in my signature for visual details on how.
    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

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi WGM, so I have done the breakpoint, when i ran the code, the debug window popped up, pressed F8 and kept pressing F8 in it highlighted the following lines and kept looping through this

    So sorry i am not understanding the theory behind this, please forgive me

    Also checked menus to find 'remove breakpoints'

    When i get this and understand your method, will this allow me to run the looped postcodes through a single URL command out side of the loop ?




    Click image for larger version. 

Name:	Capture.JPG 
Views:	19 
Size:	43.1 KB 
ID:	47696

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Pressed Ctrl+G and nothing in the immediate window

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    @ Dave,
    You mention adding 6 post codes yet to Dim only 5 pc string variables and then don't use them. Can your recordset return more then six? Can it return Nulls?
    In any case you need to add the rsPC (usually you name string variables to start with an "s") into the line inside the loop:
    Code:
    rsPC = rsPC & (Replace(Replace(rs("PostCode"), " ", "") & "/")
    .
    Now you have them all the post codes but the variable contains one extra "/? at the end. So you need to add an extra line outside the loop to remove it:
    Code:
    rsPC=Left(rsPC,Len(rsPC)-1)
    Finally add your Shell line after this.
    Learning how to step through code will help you tremendously in figuring out what's happening!

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    The reason there is nothing in the immediate window is because you have no debug.prints?
    As you press F8 and loop through the records, hover over rsPC and see what values you have each time.

    Yes, when you grasp the logic required. This is meant to show you what you are doing wrong, and teach you some basics of debugging, which you really should know by now.
    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

  11. #11
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    HI WGM and Vlad, thank you for helping, now done debug.Print on rsPC and the immediate window shows the rest of the postcodes in the rs

    The shell command now opens and adds just the single postcode when 3 are checked, the 3 are in immediate window so:

    That is now telling me the loop is working

    Will loop through on F8

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  13. #13
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Just looked at the signature as suggested and watched the debug.Print video, will give it a shot now

  14. #14
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Did you make the changes I suggested in my previous post? It should look something like this (there is no checks or logic anywhere to see how many checkbox are checked, so the code relies on the recordset rs to contain the same number of records (not null for the post codes):
    Code:
    Dim myURL As String, OpenChrome As String, rsPC As StringDim iQty As Integer'Dim pc1 As String, pc2 As String, pc3 As String, pc4 As String, pc5 As String 'Vlad you don't use them so why have them?
    Dim rs As DAO.Recordset
    
    
    
    
    
    
    
    
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE AddToRoute = Yes")
    
    
    
    
    Do Until rs.EOF
        rsPC = rsPC & (Replace(Replace(rs("PostCode"), " ", "") & "/")
        Debug.Print rsPC 
    rs.MoveNext
    Loop
    
    
    rsPC=Left(rsPC,Len(rsPC)-1) 'Vlad - remove the trailing /
    Debug.Print rsPC 
       
     myURL = "https://www.google.co.uk/maps/dir/" & rsPC
        
    OpenChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
    Shell OpenChrome & myURL, vbMaximizedFocus
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    I would expect the single postcode you get, is the last selected?
    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 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 08-14-2012, 07:06 AM
  2. writing data from recordset to table
    By akrylik in forum Access
    Replies: 5
    Last Post: 05-23-2012, 05:48 PM
  3. Edit Data in Recordset
    By Bwilliamson in forum Programming
    Replies: 3
    Last Post: 05-12-2011, 08:29 AM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  5. Sorting data in ADO Recordset
    By martinjamesward in forum Programming
    Replies: 1
    Last Post: 08-28-2009, 05:38 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