Setting the URL for a WebBrowser from a Form Variable

Tezcatlipoca

Registered User.
Local time
Today, 01:35
Joined
Mar 13, 2003
Messages
246
Hokay, I've been tinkering with this one for a while, but no luck.

Let's say a form has a browser embedded, called WebBrowser0. The OnLoad code for this form is:

Code:
Private Sub Form_Load()
    Me!WebBrowser0.Navigate "http://www.mydomain.co.uk/search.asp"
End Sub

Now the page Search.asp does nothing without the following string of arguments after it:

Code:
?id=NLAcllu9&memberno=XXXXX

where XXXXX is a 5 digit number of a person that exists in another database.

Also on my form is an unbound textbox, and a Submit button.

What I need is to allow a user to punch any 5 digit number they like into that textbox, then, when clicking submit, the embedded webbrowser takes them to that string.

For example, the user of the database enters 12345 into the box, clicks Submit and the embedded browser goes to:

Code:
http://www.mydomain.co.uk/search.asp?id=NLAcllu9&memberno=12345

I understand I'll have to save a variable somewhere, but am not sure where to start. I can, if need be, have the textbox on a different form if required, which I guess could then store the number as openargs and, when loading the webpage form, update the VB that calls the page.

Clear as mud? Yeah, for me too, but does anyone have any bright ideas?
 
Hokay, I've been tinkering with this one for a while, but no luck.

Let's say a form has a browser embedded, called WebBrowser0. The OnLoad code for this form is:

Code:
Private Sub Form_Load()
    Me!WebBrowser0.Navigate "http://www.mydomain.co.uk/search.asp"
End Sub

Now the page Search.asp does nothing without the following string of arguments after it:

Code:
?id=NLAcllu9&memberno=XXXXX

where XXXXX is a 5 digit number of a person that exists in another database.

Also on my form is an unbound textbox, and a Submit button.

What I need is to allow a user to punch any 5 digit number they like into that textbox, then, when clicking submit, the embedded webbrowser takes them to that string.

For example, the user of the database enters 12345 into the box, clicks Submit and the embedded browser goes to:

Code:
http://www.mydomain.co.uk/search.asp?id=NLAcllu9&memberno=12345

I understand I'll have to save a variable somewhere, but am not sure where to start. I can, if need be, have the textbox on a different form if required, which I guess could then store the number as openargs and, when loading the webpage form, update the VB that calls the page.

Clear as mud? Yeah, for me too, but does anyone have any bright ideas?


try something like:

Code:
Me!WebBrowser0.Navigate "http://www.mydomain.co.uk/search.asp?id=NLAcllu9&memberno=" & Me.txtYourControlName
 
try something like:

Code:
Me!WebBrowser0.Navigate "http://www.mydomain.co.uk/search.asp?id=NLAcllu9&memberno=" & Me.txtYourControlName

Ah, perfect, thanks HiTechCoach. Now I just need to tinker the an event type to attach this code to.

On a related subject, once the browser has navigated to the site, it returns data from the online database as a list of XML fields, for example:

Code:
<Member>
  <MembershipNumber>12345</MembershipNumber> 
  <MemType>TYPE</MemType> 
  <MemTypeDesc>TYPE</MemTypeDesc> 
- <Surname>
- <![CDATA[ SURNAME
  ]]> 
  </Surname>
- <Forenames>
- <![CDATA[ FORENAME
  ]]> 
  </Forenames>
  <PostCode>POSTCODE</PostCode> 
  <ClearedDate>DATE</ClearedDate> 
  </Member>

This works perfectly, it just look damn messy. Yeah, yeah, I know I can easily apply CSS style code t the asp page, but I'd prefer to handle everything from inside the database. Is there a way I can have Access, or, rather VB, grab details from within field tags on the page so I can present them as I want them?
 
You could try this:

Code:
Function Web_Search()
    
    With CodeContextObject
        Dim WebLink As String
        WebLink = GetWebPath & "search.asp?id=NLAcllu9&memberno" & .[memberno] & ""
        Application.FollowHyperlink WebLink, , True
        HideWebToolBar
    End With
End Function

GetPath

Code:
Private Function GetWebPath() As String
    GetWebPath = [URL]http://www.mydomain.co.uk/[/URL]
End Function

The AddInfo does not work in Access 2007 whereas declaring the full string does. The GetPath allows a declaration of a site rather than having to reiterate in each Function. The memberno refers to your control.

Simon
 
I'm going to venture out and take a stab.

You could do something like:
Code:
Dim lPostCode as Long

if Instr(String, "<POSTCODE>") Then
     lPostCode = Split(String, "<POSTCODE>")(1)
     lPostCode = Split(lPostCode, "</POSTCODE>")(0)

that would pull it out but I imagine it would take a while and be pretty tedious.
 
Cheers for the responses guys. Could I just ask for a little further clarification?

I guess that I'd want the results to get returned on the same form that the WebBrowser object is on. Assuming I make the aforementioned browser invisible, would the code to update the unbound textbox fields that are the search results (so one for name, one for postcode, etc.) go into the AfterUpdate event of the browser object or the OnClick event of the button that does the search?
 
Then providing in your Where Cluase on your web page it includes variables:

Request.Querystring("Name")
Request.Querystring("Postcode")

try:

search.asp?Name=" & .[Name] & "&Postcode=" & .[Postcode] & ""

Simon
 
Then providing in your Where Cluase on your web page it includes variables:

Request.Querystring("Name")
Request.Querystring("Postcode")

try:

search.asp?Name=" & .[Name] & "&Postcode=" & .[Postcode] & ""

Simon

Sorry, I probably wasn't clear. I don't need to search on anything other than the number (which HiTechCoach's code does wonderfully). This all works, and returns an XML page in the format I've outlined above within the WebBrowser object.

What I want to do eventually is hide the WebBrowser window altogether and have some kind of code that grabs the relevant details from the loaded webpage, and puts them into the right fields.

So, for example, I would have an unbound textbox on the form called txtPostCode. When the user does a search on, say, member 12345 and the postcode is listed in the XML as <POSTCODE>W1 4JH</POSTCODE>, then txtPostCode would automatically get updated with this data.

The point of all this isn't just aesthetic; if I can stript he data from the webpage search results and get it into text fields on the form, I can manipulate it in other areas of the database, which would be a massive benefit.
 
Last edited:
*** PLEASE DO NOT REPLY TO THIS THREAD. A THREAD WITH A RELEVANT TITLE HAS BEEN CREATED FOR THIS ISSUE, AND CAN BE FOUND HERE***
 

Users who are viewing this thread

Back
Top Bottom