Search code examples
vbams-accessadodbtruncatememo

Copying from server and local recordsets (Access VBA) - fields truncating after 255 characters?


Long story short, I am pulling a bunch of data from a data warehouse into a local Access DB. I'll post the code before showing what I'm doing with the first source data set. The rest of the data sets are being pulled in using the same concepts.

The local tables are pre-defined and the text fields in question are "memo" fields in the local DB. I checked and the source data being loaded into the data warehouse is not truncating these fields. Also I'm able to export the data via other applications without these fields being truncated. So there's something happening when I import the data from the data warehouse into my local access database.

Here's the relevant excerpt from my (very simple) code. I'm just matching field names and using the recordset .value property to copy the data from the server to the local table.

Any ideas?

Dim db As DAO.Database
Set db = CurrentDb

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

Dim rsServer As ADODB.Recordset
Set rsServer = New ADODB.Recordset

Dim rsLocal As Recordset
Dim fField As ADODB.Field

'Open Connection
With conn
    .ConnectionString = dataConnectionString
    .Open
End With

'*****************************
'*******Data set 1 data*******
'*****************************

'Open server DSET_1_SOURCE_DATA table
Set rsServer = conn.Execute(SQL_DSET1_SERVER)

'Open local DSET_1_LOCAL_DATA table
Set rsLocal = db.OpenRecordset(SQL_DSET1_LOCAL)

'DELETE ALL RECORDS FROM LOCAL TABLE
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE * FROM DSET_1_LOCAL_DATA")
DoCmd.SetWarnings True

rsServer.MoveFirst

Do Until rsServer.EOF
    rsLocal.AddNew

    For Each fField In rsServer.Fields
        rsLocal.Fields(fField.Name).Value = rsServer.Fields(fField.Name).Value
    Next

    recordCount = recordCount + 1
    rsLocal.Update
    rsServer.MoveNext
Loop

Solution

  • I solved my own issue. Which wasn't the issue I thought I had.

    Data was copying from my server recordset into my local recordset just fine. It was also updating the appropriate tables just fine. What I didn't realize was that exporting from a SELECT query directly into EXCEL truncates memo fields after 255 characters. Making the final query into a table and then exporting that solved my problem.

    Thank you to everyone who responded trying to help.