Cannot seem to set a field flags on import (1 Viewer)

StuartWB

New member
Local time
Today, 15:34
Joined
Oct 7, 2011
Messages
9
Hi

I have an import routine that need to detect the type of data being imported based on the model type. The data are on spread sheets that are the same format but depending what the value is in the model field will determine what flags are to be set. my code does not seem to make any difference I have tried "If Then Else" and "If Then ElseIf" but it seem to treat both import file the same.
Any help appreciated.


Code:
Public Sub ImportConfig()

  On Error GoTo ErrorHandler

  Dim rsImport As DAO.Recordset
  Dim rsExport As DAO.Recordset
  Dim fld1 As DAO.Field
  Dim fld2 As DAO.Field
  Dim fldName As String
  Set rsImport = CurrentDb.OpenRecordset("Product")
  Set rsExport = CurrentDb.OpenRecordset("Import")

  rsExport.AddNew

  Do While Not rsImport.EOF
    fldName = rsImport!Desc
    Debug.Print fldName & " " & rsImport!Serial
    rsExport.Fields(fldName) = rsImport!Serial
    Debug.Print fldName & " " & rsExport!Serial
    rsImport.MoveNext
    rsExport![xxx] = Form.[xxx]

          If rsExport.Fields(fldName) = "Model1" Then
            rsExport.Fields("Model1") = -1
            rsExport.Fields("Model2") = 0
            rsExport.Fields("Delete") = 0

           ElseIf rsExport.Fields(fldName) = "Model2" Then
            rsExport.Fields("Model1") = 0
            rsExport.Fields("Model2") = -1
            rsExport.Fields("Delete") = -1

    End If
     Loop
         

  rsExport.Update
   
ErrorHandler:
Resume Next

End Sub
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 15:34
Joined
Sep 21, 2011
Messages
7,112
Walk through the code with F8 and see what it is doing, not what you think it is doing?

That is how I get to errors in logic like this.?
 

arnelgp

error reading drive A:
Local time
Today, 23:34
Joined
May 7, 2009
Messages
10,834
you need to re-locate some codes:
Code:
Option Compare Database
Option Explicit

Public Sub ImportConfig()
 
    On Error GoTo ErrorHandler
 
    Dim rsImport As DAO.Recordset
    Dim rsExport As DAO.Recordset
    Dim fld1 As DAO.Field
    Dim fld2 As DAO.Field
    Dim fldName As String
    Set rsImport = CurrentDb.OpenRecordset("Product")
    Set rsExport = CurrentDb.OpenRecordset("Import")
 
 
 
    Do While Not rsImport.EOF
        rsExport.AddNew
        fldName = rsImport!Desc
        Debug.Print fldName & " " & rsImport!Serial
        rsExport.Fields(fldName) = rsImport!Serial
        Debug.Print fldName & " " & rsExport!Serial
        rsExport![Weapon] = Form.[Weapon]
 
        If rsExport.Fields(fldName) = "Model1" Then
            rsExport.Fields("Model1") = -1
            rsExport.Fields("Model2") = 0
            rsExport.Fields("Delete") = 0

        ElseIf rsExport.Fields(fldName) = "Model2" Then
            rsExport.Fields("Model1") = 0
            rsExport.Fields("Model2") = -1
            rsExport.Fields("Delete") = -1
 
        End If
        rsExport.Update
        rsImport.MoveNext
    
    Loop
          

    
ErrorHandler:
    Resume Next
 
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:34
Joined
Feb 19, 2002
Messages
30,036
Why is rsExport bound to "Import" when you have a recordset labeled rsImport?
 

Users who are viewing this thread

Top Bottom