You are absolutely right! I unchecked "Microsfot Office 14.0 Access Database engine object library" and I was able to successfully add DAO 3.6 reference. However, neither of these references will successfully run the code below that I inherited from another
user (I have only basic knowledge of VBA). I have determined that the code crashes at Set rst = db.OpenRecordset(sSql, dbOpenSnapshot). The code works very successfully in Access 2003 databases. Do you have any ideas/suggestions to make this work?
The purpose of the code is explaineded below. A coworker found it years ago online.
'> Hello,
'> I would Combining values from fields of more than 1 record in 1 field.
'> For example
'>
'> Name
firstname number
'>
'> Heide
Marcel 1
'> Heide
Marcel 2
'> Heide
Marcel 3
'> Kooring
Yvonne 7
'> Kooring
Yvonne 14
'>
'> Number is a unique number
'>
'> Result should look like
'> Heide
Marcel 1,2,3
'> Kooring
Yvonne 7,14
VBA CODE:
Option Compare Database
Option Explicit
Public Function SupInd() As Boolean
On Error Resume Next
Dim db As DAO.Database, rst As DAO.Recordset, sSql As String
Dim strColA As String, strColB As String
Set db = CurrentDb()
' Delete Table, if exists
If DCount("*", "MsysObjects", "[Name]='tbl_SupplierIndicator'") = 1 Then
DoCmd.DeleteObject acTable, "tbl_SupplierIndicator"
End If
sSql = "CREATE TABLE tbl_SupplierIndicator (Duns Integer, SupplierIndicator Text(5))"
db.Execute sSql
sSql = "SELECT Duns, Supplier_Indicator FROM qry_DivRegSupplierIndicator " _
& "ORDER BY Duns, SupplierIndicator ASC"
Set rst = db.OpenRecordset(sSql, dbOpenSnapshot)
If Not rst.BOF And Not rst.EOF Then
rst.MoveFirst
strColA = rst!Duns
strColB = rst!SupplierIndicator
rst.MoveNext
Do Until rst.EOF
If strColA = rst!Duns Then
strColB = strColB & ", " & rst!SupplierIndicator
Else
sSql = "INSERT INTO tbl_SupplierIndicator (Duns, SupplierIndicator) " _
& "VALUES('" & strColA & "','" & strColB & "')"
db.Execute sSql
strColA = rst!Duns
strColB = rst!SupplierIndicator
End If
rst.MoveNext
Loop
' Insert Last Record
sSql = "INSERT INTO tbl_SupplierIndicator (Duns, SupplierIndicator) " _
& "VALUES('" & strColA & "','" & strColB & "')"
db.Execute sSql
End If
Set rst = Nothing
Set db = Nothing
End Function