shanesuzanne
New Member
- Joined
- Dec 1, 2016
- Messages
- 21
The code below takes a table and adds a count to the rows based on unique values. Here is an example of it's output:
row coName Sequence
1 ABC 1
2 XYZ 1
3 ABC 2
4 RST 1
5 ABC 3
6 XYZ 2
It works perfectly - EXCEPT when there is an apostrophe or a double quote in the value - and I have both. Since the coName field is the legal company name, I don't want to remove the punctuation from the data in the table. I've tried different approaches for hours, but I can't get it to work. Here is where it has the error: coName = '" & tblDistinct.Fields("coName").Value &
I get run-time error -2147217900 (80040e14) "Syntax error (missing operator) in query expression 'coName='ABC's' 'Order By Record".
Any ideas?
row coName Sequence
1 ABC 1
2 XYZ 1
3 ABC 2
4 RST 1
5 ABC 3
6 XYZ 2
It works perfectly - EXCEPT when there is an apostrophe or a double quote in the value - and I have both. Since the coName field is the legal company name, I don't want to remove the punctuation from the data in the table. I've tried different approaches for hours, but I can't get it to work. Here is where it has the error: coName = '" & tblDistinct.Fields("coName").Value &
I get run-time error -2147217900 (80040e14) "Syntax error (missing operator) in query expression 'coName='ABC's' 'Order By Record".
Any ideas?
Code:
Sub addSeq()
Dim tblDistinct As New ADODB.Recordset
Dim Count As New ADODB.Recordset
tblDistinct.Open "Select Distinct coName From imports", Application.CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
Do Until tblDistinct.EOF
Count.Open "Select * From imports Where coName = '" & tblDistinct.Fields("coName").Value & "' Order By Record", Application.CurrentProject.Connection, adOpenKeyset, adLockPessimistic
Do Until Count.EOF
Count.Fields("Sequence") = Count.AbsolutePosition
Count.MoveNext
Loop
Count.Close
F4.MoveNext
Loop
tblDistinct.Close
End Sub