Understanding Errors

  • I have this sqlquery that I am writing:

    Private Sub Command1_Click ()

    Dim Irepsonse as Integer

    Iresponse = msgbox("press a button", vbabortretryignore, "Chapter 4")

    Select Case iresponse

    Case vbabort

    Me.lblresponse.caption = "You pressed abort."

    Case vbretry

    Me.lblresponse.caption = "you pressed retry."

    Case vbignore

    Me.lblresponse.caption = "you pressed ignore."

    End Select

    End Sub

    But when trying to run it I get an error string that says:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'Command1_Click'.

    Msg 156, Level 15, State 1, Line 6

    Incorrect syntax near the keyword 'Case'.

    Msg 102, Level 15, State 1, Line 17

    Incorrect syntax near 'Sub'.

    How am I supposed to know where the errors are since I dont know what msg, level, or state mean?

  • You have mixed Visual Basic language (private sub....) with T-SQL (Select Case ....). Those languages can't be combined in one statement.

    The code you stated is more Visual Basic then T-SQL and should be created in Visual Studio instead of SQL Server Management Studio.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • Yeah,

    I just realized what book I was reading. Been spending so much time reading books on SQL language and VBA that I am getting mixed up...... Thanks for the reminder...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply