?
Solved

Automate IE from VB - site with  onclick = "return confirm('Update?')"

Posted on 2006-04-23
12
Medium Priority
?
1,869 Views
Last Modified: 2008-01-09
Hi,
I'm working on automating updating information on a web-site from VBA. The site use  "onclick = "return confirm('Update?')""  on the submit button.

Is there a way to "click" on the OK button on the alertbox?
Or somehow bypass the alertbox?

I'm using code like this:

    Set oIE = New SHDocVw.InternetExplorer
   oIE.Navigate "https://ddsmedlem.cbrain.dk/member.aspx?func=member.edit&mno=" & c.Value
   oIE.Document.all("Address1:_ctl0").Value = c.Offset(0, 3).Value
   oIE.Document.all("Address1:_ctl1").Value = c.Offset(0, 4).Value
   oIE.Document.all("submitButton").Focus
   oIE.Document.all("submitButton").Click

0
Comment
Question by:thor_ostergaard
  • 7
  • 5
12 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 2000 total points
ID: 16519244
Do:

oIE.Document.all("formName").Submit


to bypass.
0
 

Author Comment

by:thor_ostergaard
ID: 16519260
Great - thanks
0
 

Author Comment

by:thor_ostergaard
ID: 16519288
Sorry - did'nt work - the information is not updated.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:thor_ostergaard
ID: 16519301
It is a .net site and the problem is properly a missing postback
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 16521934
Is that the only javascript in the onclick of the submit button?  Clicking submit and directly submitting the form should have no change in the way the data is submitted.
0
 

Author Comment

by:thor_ostergaard
ID: 16522302
Nope - it is asp.net and there are a few more scripts
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 16524393
It shouldn't matter what the server side language is...but if they coded the server side to specifically look for the button click, and not just the form submitted, then that will be a problem.

All I can think of is to trap for that event in your code, and try to automatically override the event handler with your own.  To do this, go to Project -> References and select HTML Object Library.  Then in your code module, place this at the top:

Private WithEvents btnSubmit As HTMLButtonElement (<~~ I think that is what it is called)

After navigating to the page, do:

Set btnSubmit = oIE.Document.all("submitButton")

You should be able to select, from your code module, the btnSubmit object in the top left dropdown box.  Once selected, you should see all the events in the right hand dropdown box (like any other control you place on a form, for example).  You should be able to select the onclick event.  Selecting it should give you something like:


Private Function btnSubmit_onclick() As Boolean

End Function


Inside that function, simply put:

btnSubmit_onclick = True


Then run your code as you had it before where it clicked the button to submit the form.
0
 

Author Comment

by:thor_ostergaard
ID: 16532237
It's not possible to declare the HTMLButtonElement with events :-(
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 16533949
You must be writing your code in a standard .bas module.  It must be in a form or class module to utilize events of any kind.
0
 

Author Comment

by:thor_ostergaard
ID: 16534680
I'm running in a module now and the new eventhandler is called, but after the eventhandler on the site :-(
0
 

Author Comment

by:thor_ostergaard
ID: 16534729
Wow :-))))

btnSubmit.onclick = "" 

did the trix :-)

I'm running now. Thanks for your help.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 16534752
I guess that would make sense too...just delete the javascript code that executes when clicked.  Good job.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question