I found another way to force MS Access to crash to desktop, and it’s shockingly simple.
Sub SQLTest()
Dim Query As ADODB.Command
Set Query = New ADODB.Command
With Query
.ActiveConnection = CurrentProject.Connection
.CommandText = "SELECT ?"
.Parameters.Append .CreateParameter(, adChar, , 1, "a")
.Execute
End With
End Sub
In addition to the reliable crash, Microsoft provided some poor documentation stating, “The minimum syntax for a SELECT statement is: SELECT fields FROM table
.” Well there’s no problem at all running a statement like SELECT 'Hello'
and I was surprised I couldn’t parameterize it for input testing.
Workaround
The same query will succeed (not crash) if you specify a name for the result column. There is no logical reason for it to work one way and not the other, but it looks like this:
Query.CommandText = "SELECT ? AS 'MyColumn'"
Ironically, the name doesn’t have to be a valid string. I was able to get the same result using this nonsense:
Query.CommandText = "SELECT?AS'"
MS Word
Outside of the Access environment, one way to reproduce this bug is to connect to an existing accdb file. Here are the steps:
- Existing file named
C:\example.accdb
If you want to download a file, see the previous post. - Open Word and click the New and Blank document buttons.
- Press Alt+F11 to open the VBA window.
- Go to the Insert menu and click Module.
- Go to the Tools menu and click References.
- Select the Microsoft ActiveX Data Objects 6.1 Library.
- Click OK.
- Paste the following code:
Sub SQLTest()
Dim Conn As ADODB.Connection
Dim Query As ADODB.Command
Set Conn = New ADODB.Connection
Set Query = New ADODB.Command
With Query
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\example.accdb"
.ActiveConnection = Conn
.CommandText = "SELECT ?"
.Parameters.Append .CreateParameter(, adChar, , 1, "a")
.Execute
End With
End Sub
After that, just press F5 to crash the program. Keep in mind you will lose all unsaved work in the program.