Hey there guys, I know you must have seen this 100 times before, but I cannot for the life of me see where I have gone wrong. The first time the code is executed, it loads IE on the page desired, then throws up the error:

Runtime error '91'
Object variable or With Block variable not set

Code:
Option Explicit
Private Sub ERGLoginbtn_Click()
Dim IE As Object
     
    Set IE = CreateObject("InternetExplorer.application")
    IE.navigate ("https://apprenticeshipvacancymatchingservice.lsc.gov.uk/navms/forms/candidate/CandidatesLogin.aspx")
    IE.Visible = True
     
    While IE.Busy
        DoEvents
    Wend
    IE.document.getElementById("ctl00_ContentBody_LoginControl1_UsernameTextBox").Value = "XXXXX"
    IE.document.getElementById("ctl00_ContentBody_LoginControl1_PasswordTextBox").Value = "XXXXX"
    IE.document.all("ctl00$ContentBody$LoginControl1$LoginButton").Click 'click the login button
    While IE.Busy
        DoEvents
    Wend
     'any more code
     'if the user closes the web page then you don't need the quit
     'set IE to nothing at the end of macro
    Set IE = Nothing

End Sub
Then if I run it again immediatley afterwards, it works fine... the error is thrown up on the line in bold, so I would assume that it would be the same for the following 3 lines.... something I have done somewhere must be wrong, it's probably something really simple, but hey, i'm an amateur LOL

cheers for any help in advance
Polecat