ADODB recordset returns Runtime error 3021 Either BOF or EOF is true...

AndyMb

New Member
Joined
Jul 1, 2015
Messages
20
Hello,

I have a UNION query in Access that merges two tables - OLD vehicles and NEW vehicles

I have a form in Excel that brings Vehicle data in from that UNION query.

So when a user searches a vehicle reg number it matches the reg and should return other details about the vehicle.

When I search (using the form) for a reg that originated from the OLD vehicles table, it works fine. When I search a reg that originated from the NEW vehicle table I get the error that's in my title.

If I run the UNION query in Access and search for a reg from the NEW table it's there, so I know it exists.

Can anyone help me understand why I get this error?

"OrderBookMerge" is my UNION query

Here is my code in excel:

VBA Code:
Private Sub CommandButton5_Click()

Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim SearchX As Variant


Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
    "Data Source=C:\Data\QCandWarranty.accdb"
Set rs = New ADODB.Recordset
rs.Open "OrderBookMerge", cn, adOpenKeyset, adLockOptimistic, adCmdTable


SearchX = ComboBox1.Value
Debug.Print SearchX
Set rs = cn.Execute("SELECT [WoNo],[LineX],[Cust],[Vehicle],[BOM], [SpecNo], [Chassis], [VehicleUniqueID] " & "FROM [OrderBookMerge]" & "WHERE [Reg] = '" & SearchX & "'")



TextBox1.Text = rs.Fields("Vehicle")
TextBox2.Text = rs.Fields("Cust")
TextBox3.Text = rs.Fields("BOM")
TextBox4.Text = rs.Fields("SpecNo")
TextBox5.Text = rs.Fields("WoNo")
TextBox6.Text = rs.Fields("LineX")
TextBox7.Text = ComboBox1.Value
TextBox8.Text = rs.Fields("Chassis")

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
L

Legacy 456155

Guest
I have no idea why. Maybe compatibility? Other dialects of SQL such as T-SQL use % as the wildcard char.
 
L

Legacy 456155

Guest
My pleasure. 14 Posts for one character! Have a nice day! :)
 

Watch MrExcel Video

Forum statistics

Threads
1,129,407
Messages
5,636,107
Members
416,898
Latest member
imsorrymen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top