Hi everyone!

I have a webbrowser control that opens a website and automatically fill in the textboxes on the forms. I am done with that part but im having problems with the loop.

The data are stored in the database where i populate it using Msflexgrid. And i use two textboxes for ranges like process 1-5 or 10-20... etc coz i have more than 10,000 records.

I want to leave my computer to process it but for the sake of testing i put number ranges that is incorporated in my loop.


Code:
Dim x As Long ' loop counter

tempnum = CLng(txtFrom.Text)

For x = CLng(txtFrom.Text) To CLng(txtTo.Text)

    With WebBrowser1
        .Document.All("Add").Click

        ' error on this part coz the above code is not yet completed
        .Document.All("Firstname").Value = MSFlexGrid1.TextMatrix(tempnum, 1) 
        .Document.All("Lastname").Value = MSFlexGrid1.TextMatrix(tempnum, 2)
        .Document.All("Save").Click
        tempnum = tempnum + 1
    End With
Next x

I'm having problems with the click event coz it will not wait for the document to complete before firing the next command. Is there a workaround for this delay without moving the rest of the function to "WebBrowser1_DocumentComplete" event?