Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    INSERT IN RS.... (why this error....)

    I have code error se images with this code(arranged old macro from VBA for Excel):

    Sub ELENCO()

    Dim CN As New ADODB.Connection
    Dim RS As New ADODB.Recordset
    Dim RIGA As String
    Dim RIGA1 As String

    Set CN = New ADODB.Connection
    Set RS = New ADODB.Recordset

    Set myOLApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOLApp.GetNamespace("MAPI")
    Set myGAddressList = myNameSpace.AddressLists("Elenco Indirizzi Globale")
    Set myGEntries = myGAddressList.AddressEntries

    CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:TEST_MDBSTORICO_INPS.MDB;Persist Security Info=False"
    RS.Open "USER_NAME", CN, adOpenKeyset, adLockOptimistic, adCmdTableDirect

    For Each LISTA In myGEntries

    If Left(LISTA, 5) = "ATM65" Or Left(LISTA, 5) = "ATM45" Then

    For Each Nom In LISTA.Members

    With RS

    If Not RS.BOF Then
    RS.MoveFirst
    End If

    If RS.EOF = True Then

    LISTA_AG = Right((LISTA), 4)
    LISTA_MATR = Right(UCase(Nom.Address), 7)
    LISTA_NOM = UCase(Nom)

    .Fields("AGENZIA").Value = LISTA_AG
    .Fields("MATRICOLA").Value = LISTA_MATR
    .Fields("NOMINATIVO").Value = LISTA_NOM
    .Update
    End If
    End With

    'RIGA = RIGA + 1

    Next Nom

    End If

    If LISTA = "ATM6552" Then
    GoTo FINE
    End If

    Next LISTA

    FINE:

    RS.Close
    Set RS = Nothing

    CN.Close
    Set CN = Nothing

    'ActiveWorkbook.Save
    'Sheets("ATM").Range("A2").Select
    MsgBox ("IMPORT TERMINATO!")

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: INSERT IN RS.... (why this error....)

    Shouldn't you add a new record? Otherwise, the line

    If RS.EOF = True Then

    will cause the subsequent code to fail.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •