My Assistant
![]() ![]() |
|
|
Apr 2 2012, 04:07 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 190 |
Hi
I have take this code from a web site to try to understand how to retrieve web date using access... It's giving to me a error when i try to run it "object variable or with block variable not set" and it points to the line WebBrowser1.navigate "http://www.google.com" Any idea how to fix it ? CODE Option Compare Database Sub Main() Dim WebBrowser1 As HTMLObjectElement 'what is the page you want to pull up in your browser (ie icq.com/sms) WebBrowser1.navigate "http://www.google.com" 'sometimes there are timing issues, so issue a couple of doevents so the browser responds DoEvents: DoEvents: DoEvents Do While WebBrowser1.Busy 'wait until the page loads by looping DoEvents Loop Set doc = WebBrowser1.Document 'access the document properties of the current page DoEvents Do While WebBrowser1.Busy DoEvents Loop 'if you pull your page up in IE and you view the source, 'you can find the form variables that you want to fill in 'I'm sure there are other ways to iterate through the form ' to get them, but I never could figure it out. returnValue = FillForm("q", "this is my search criteria", False) WebBrowser1.Document.Forms(0).submit End Sub Public Sub ClickLink(doc, LinkText As String) For i = 0 To doc.links.length - 1 If InStr(LTrim(RTrim(doc.links(i).outerText)), LinkText) > 0 Then doc.links(i).Click Exit For End If Next i End Sub Function FillForm(ByVal formtag, ByVal FillValue, ByVal isCombo As Boolean) As Boolean Dim elemcollection As IHTMLElementCollection Dim obj As Object Dim element2 As HTMLInputElement Dim element As HTMLInputElement If Not isCombo Then WebBrowser1.Document.Forms(0).elements(formtag).Value = FillValue Else WebBrowser1.Document.Forms(0).elements(formtag).selectedIndex = Val(FillValue) End If End Function thanks in advance |
|
|
|
Apr 2 2012, 04:29 PM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi,
Not sure if HTMLObjectElement is what you really need there. Try changing the line from: Dim WebBrowser1 As HTMLObjectElement to: Dim WebBrowser1 As New InternetExplorer Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 2 2012, 05:21 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 190 |
Hi
After changing that line to what you said it's giving to me a new error... "Object required" The error points to the line WebBrowser1.Document.Forms(0).elements(formtag).Value = FillValue Like i said i have copy the code from a site and i don´t understand very well yet this vba thing. Thanks in advance for the help... |
|
|
|
Apr 2 2012, 08:41 PM
Post
#4
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi,
Try declaring your web browser object outside of any subs. It's possible that the error means that the object went out of scope. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 3 2012, 03:10 AM
Post
#5
|
|
|
UtterAccess Addict Posts: 190 |
Hi
It have gave some other's error's and because of that i have decide starting from scratch and doing one my self instead trying to use some code founded... Even that i don´t understand why sometimes the code don´t works i have made already some progress... One example what i don´t understand, why this don´t works ? html.getElementsByClassName("ref").Item(0).textContent I guess the problem in on the textContent propriety but to sort it out i have use this and it works html.getElementsByClassName("ref").Item(0).getElementsByTagName("B").Item(0).innerHTML but i would like to know why the textContent is not working , i am doing something wrong ? note: i am using the MSHTML.HTMLDocument in the html variable Thanks in advance |
|
|
|
Apr 7 2012, 07:16 AM
Post
#6
|
|
|
UtterAccess Addict Posts: 190 |
Hi
Any idea why textContent does not work ? It seems that sometimes the innerHTML have more B tags on it and the other way around that i can see is making a while to retrieve them all (if more that one)... But the easy way is to make the textContent working... Any idea... Thanks in advance |
|
|
|
Apr 7 2012, 10:06 AM
Post
#7
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi Miguel,
I really don't have any idea but you could try these variations to see if any of them works: html.getElementsByClassName("ref")[0].textContent html.getElementsByClassName("ref")[0].innerText html.getElementsByClassName("ref").Item(0).getElementsByTagName("B")[0].textContent html.getElementsByClassName("ref").Item(0).getElementsByTagName("B")[0].innerText Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 7 2012, 10:44 AM
Post
#8
|
|
|
UtterAccess Addict Posts: 190 |
Hi
Nop, nothing... All them always say "Object doesn't support this property or method (Error 438)" But when you press F2 in the Microsoft Visual Basic and you look for the textContent property the class MSHTML.HTMLDocument have it... I have try as well to add another class that have the same property but it always give the same error. Any help regarding how to do it will be nice... Thanks in advance |
|
|
|
Apr 7 2012, 10:52 AM
Post
#9
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi Miguel,
It might help if you could post the actual code you're using now or a zip copy of your file. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 7 2012, 11:35 AM
Post
#10
|
|
|
UtterAccess Addict Posts: 190 |
Hi
There he is the code... Sometimes the CODE html.getElementsByClassName("ref")(0).innerHTML retrieves CODE <b>Travessa da Fé, Quiaios, 3080 Figueira da Foz, Coimbra</b> and other's retrieves CODE <b>Travessa da</b> Fé, Quiaios, <b>3080 Figueira da Foz, Coimbra</b> thats why using the textContent will be beater, but for some reason it don´t works CODE Private Sub Comando17_Click() WebBrowser1.navigate ("http://maps.google.com/maps?f=q&source=s_q&hl=pt-PT&authuser=0&q=loc:" & Rua.Value & "," & Cidade.Value & "," & Concelho.Value & "," & Pais.Value) Do While WebBrowser1.readyState <> 4 DoEvents Loop Dim html As MSHTML.HTMLDocument Set html = WebBrowser1.Document If ListStreet.ListCount > "0" Then Call RemoveAllItemList End If totalstreet = html.getElementsByClassName("ref").length For i = 1 To totalstreet AddItemToEnd ListStreet, i & "," & html.getElementsByClassName("ref").Item(i - 1).getElementsByTagName("B").Item(0).innerHTML Next i MsgBox (html.getElementsByClassName("ref")(0).innerHTML) End Sub Function AddItemToEnd(ListStreet As ListBox, _ ByVal strItem As String) strItem = Replace(strItem, ",", ";", "1", "3") ListStreet.AddItem Item:=strItem End Function Private Sub RemoveAllItemList() Do While ListStreet.ListCount ListStreet.RemoveItem ListStreet.ItemData(0) Loop End Sub Thanks in advance |
|
|
|
Apr 7 2012, 11:39 AM
Post
#11
|
|
|
UtterAccess Addict Posts: 190 |
Hi
Here is the zip of the code will the forms as well... If you change the Rua/Largo input just for "Fé" and press the button it will retrieve the code with more tags... If you don´t change and press the button it will be fine and retrieve the code with one tag only. Thanks in advance
Attached File(s)
|
|
|
|
Apr 10 2012, 03:06 PM
Post
#12
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi Miguel,
I'm sorry. There must be a difference in our version of Access. My copy does not have the "getElementsByClassName" method. I just get an error. Can you describe what you're trying to put in the Listbox? Is it the list of alternative locations/addresses? Just my 2 cents.... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 10 2012, 04:22 PM
Post
#13
|
|
|
UtterAccess Addict Posts: 190 |
Hi
If you go to http://maps.google.com/ and search fr this "loc: Fé,,Figueira da Foz,Portugal" on the left panel it will appear other's locations in the same area that have "Fé" on the street or alley name... In the List-box is to appear that... In that example that i gave will appear: 1- R. da Fé - Figueira da Foz 2 - Travessa da Fé - Quiaios 3 - R. da Fé - Ferreira-a-Nova 4 - R. da Fé - Lavos 5 - Beco da Fé - Paião 6 - Beco da Fé - Maiorca 7 - R. da Fé - Marinha das Ondas 8 - Beco da Fé - Lavos 9 - R. Fé - Marinha das Ondas That part i already made now... But i was wondering why the textContent function is not working because according to F2 in the MVB program exits on that class... It is to add as well when i click on the list-box he will move the Google maps to that particular street It will be to ad as well an "all" on list-box to show in Google maps all the locations at the same time (this part i have no idea how to do it yet), trying to figured how the guy in the Google Maps Class Module have done it...) It seems that as well when we make a search sometimes he extend is range to other's "states", if you guys have any idea how to restrict the search just for one specific search it will be nice to know it. Thanks in advance |
|
|
|
Apr 10 2012, 06:43 PM
Post
#14
|
|
|
UtterAccess Addict Posts: 190 |
Hi
I forgot to mention that probably it don´t work on yours because you need to reference the corrects files to the access... I don´t understand my self very well that part yet but go to Tools --> Reference in Microsoft Visual Basic and active the: Microsoft HTML Object Library I think the rest you don´t need i have some others active but i guess it's not needed... By the way and for that ones that understand about this reference thing, is there any way to active them using vba ? I am asking this because it's stupid that when we create or give access to the file when we open it, the things does not work properly because the references are not active... Have a nice day... |
|
|
|
Apr 10 2012, 09:12 PM
Post
#15
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi Miguel,
No, I didn't need to set a reference to the HTML library because once you set the reference in the database, it stays with the database file. And since I just downloaded a copy of your database, that reference is already selected when I opened it on my machine. But for some reason, when I type html. in the code window, the Intellisense does not list getElementsByClassName. I know that Microsoft sometimes disable/enable certain functionalities in their software for Internaltional market. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Apr 10 2012, 09:25 PM
Post
#16
|
|
|
Access Wiki and Forums Moderator Posts: 48,059 From: SoCal, USA |
Hi Miguel,
Never mind... I WAS indeed using a different version of Access than you were. I forgot that you said you were using Acc2010, and I was trying to use Acc2007. I just tried it using 2010 and it worked (I think). Not sure if this is what you meant. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Attached File(s)
|
|
|
|
Apr 11 2012, 03:25 AM
Post
#17
|
|
|
UtterAccess Addict Posts: 190 |
Hi
With a simple line that you have replaced and worked... hehehe nice... I am not sure now, but i think i have try that and did not worked correctly but maybe the circumstances were different i don´t remember correctly now as well... QUOTE I just tried it using 2010 and it worked (I think). Not sure if this is what you meant. Not really... i was starting to think that you need to reference them in the access manually. Glad that we don´t... Well about the project i think i will change the List-Box origin line to "table" instead to "values list"... I need to have as well the coordinates and the link of the streets on it but not on the list-box... I was working on that but i have no idea how to make that i have no idea how to create tables in vba... I was trying to test some examples that the Microsoft Visual Basic has but they don´t work i guess i need to reference the correct library but i have no idea with one is the correct one... Have a nice day This post has been edited by Miguel_A: Apr 11 2012, 03:26 AM |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 23rd May 2013 - 06:53 PM |