empty recordset with memo field

Big_Ape

New Member
Joined
Sep 23, 2015
Messages
3
hi all,

I am having a frustrating issue and was hoping someone might have had some experience with it.

I have some code in Excel which runs some SQL on an Access DB and returns a recordset with the result.

Now, one of the fields is a memo field. I know that memo fields can be problematic, and I hear of people saying that it only retuns 250 characters, etc when they run it, which I am prepared to deal with (by splitting it up, eg 'left(Notes, 250) as Notes1, mid(Notes, 251, 250)as Notes2, mid(Notes, 501, 250) as Notes3,'...etc). However the problem I have is that when I select the memo field to be selected the recordset is literally empty (not just truncated). Even when I used things in the SQL statement like 'SELECT left(memofield, 10) FROM table". The code I am using to get the data is below:

Code:
Sub GetRecordset(DBSource As String, Qry As String, DestRs As Recordset)

Dim cn As ADODB.Connection
Dim i As Long
Dim j As Long
    ' connect to the Access database
    Set cn = New ADODB.Connection
    
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBSource & ";Persist Security Info=False;Jet OLEDB:Database Password=" & PWord & ";"
    
    ' open a recordset
    Set DestRs = New ADODB.Recordset
    
    DestRs.Open Qry, cn, adOpenForwardOnly, adLockReadOnly, adCmdText

End Sub

The SQLSTr can be as simple as "SELECT Memofield from table" and it does this.

I have messed around with different variables with the .open command, etc, but just cant seem to get it to work. It is only when I include the said memo field in the SQL's 'SELECT' statement. It doesnt even return anything in the other non-memo fields when it is included. It is just empty. if I dont include it in the SQL's SELECT statement, it is fine.

Anyway, and help would be appreciated.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Your connection string looks odd, why do you have references to ACE and Jet?
 
Upvote 0
This is the conneciton string i used when getting data.

I have tried it with:

I have tried it with cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBSource & ";Persist Security Info=False;Jet OLEDB:Database Password=" & PWord & ";"

but I still get the same issue.

How would you suggest I do it?
 
Upvote 0
How are you verifying the recordset is empty?
 
Upvote 0
Hmm scratch that the connection string is correct, just odd.

Could you post the SQL you're using?
 
Upvote 0
Hi,

believe it or not, you have helped me solve the issue.

by you asking me to send the SQL it forced me to trim it down, and in the process discovered it was the 'Like' criteria that was doing it. Instead of using * as a wildcard you have to used % if it is via ADO. as a result, running the SQL directly in Access worked, but not via the code.

Thanks,
 
Upvote 0

Forum statistics

Threads
1,221,902
Messages
6,162,724
Members
451,782
Latest member
LizN

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
Back
Top