Concatenation issues in VBA

Timtropolis

Registered User.
Local time
Today, 13:30
Joined
Jun 17, 2004
Messages
84
Greetings all,

I am having some difficulties with my code and was wondering is someone could help. I'm basically writing a loop which will scroll thru each column in a record, check to quotes and strip them out. The code is as follows:
Code:
        Do Until y > z
            If Right("rst!Field" & y, 1) <> Chr(34) Then
                'With rst
                    rst.Edit
                    rst!field &  y = Left((rst!field4), Len(rst!field4) - 1)
                    rst.Update
                'End With
            End If
            y = y + 1
        Loop

notes: y=current column count, z= total column count

The first occurence on line 2 "Right("rst!Field" & y, 1)" works fine , however I cannot get line 5 to work at all. I have tried a couple of different variations with quotes and variables but I keep getting compile error messages.

I believe I'm close but need a little help. If anyone can provide some assistance, it would be greatly appreciated.

TIA,
Tim
 
Here's an example that you might be able to adapt for your project...

Code:
Dim rs         As New ADODB.Recordset
Dim fld        As ADODB.Field
Dim sSQL       As String
Dim sCrit      As Long

sCrit = 1

sSQL = "SELECT TblNames.* " & _
       "FROM TblNames " & _
       "WHERE TblNames.NumID=" & sCrit

With rs
   .ActiveConnection = CurrentProject.Connection
   .LockType = adLockOptimistic
   .CursorType = adOpenKeyset
   .Source = sSQL
   .Open Options:=adCmdText
End With

If rs.RecordCount > 0 Then
   For Each fld In rs.Fields
      Select Case fld.Type
         
         Case 202, 200, 130
            If Right(fld.Value, 1) = Chr(34) Then
               fld.Value = Left(fld.Value, Len(fld.Value) - 1)
            End If
            
      End Select
   Next fld
   rs.Update
End If

rs.Close
Set rs = Nothing

Regards,
Tim
 
:) That did it, tyvm Pono for your help!!
 

Users who are viewing this thread

Back
Top Bottom