Hey everyone,
I'm trying to import a table using xml file into my access project.
First I exported the table the easy way and saved it on my desktop, and now I'm trying to write a vb code for a button on a form that will import it. I have few other project that do that and I tried to copy the code but no matter what I try it gives me an error - "compiler error: user-defined type not defined"
I googled this error but can't really understand what's the problem. I mean if this code works in other project it should be correct, right?
so what I did is I just paste the form from the working project and change the path, and the table details in the vb code. and still I get that error.
is there something I'm missing???
please help!!
here's my code-

Private Sub ImportBtn_Click()

Application.ImportXML "C:\Documents and Settings\xxxxxxxx\Desktop\tblNG.xml"

Dim destinationRS As New ADODB.Recordset
 destinationRS.Open "tblNG", CurrentProject.Connection, adOpenDynamic, adLockPessimistic

  Dim sourceRS As New ADODB.Recordset
  sourceRS.Open "tblNG", CurrentProject.AccessConnection, adOpenDynamic, adLockPessimistic
  sourceRS.MoveFirst
  destinationRS.MoveFirst
  Dim flag As Integer
  flag = 0
  
  While Not (sourceRS.EOF)
  flag = 0
       Do While Not (destinationRS.EOF)
          If (destinationRS.Fields("Id") <> sourceRS.Fields("Id")) Then
                destinationRS.MoveNext
                flag = 1
          Else
                sourceRS.MoveNext
                flag = 0
                Exit Do
          End If
        Loop
    If (flag = 1) Then
    destinationRS.AddNew
    destinationRS.Fields("Id") = sourceRS.Fields("Id")
    destinationRS.Fields("FirstName") = sourceRS.Fields("FirstName")
    destinationRS.Fields("LastName") = sourceRS.Fields("LastName")
   sourceRS.MoveNext
    End If
  Wend
  destinationRS.Update
  destinationRS.Close
  sourceRS.Close
  DoCmd.DeleteObject acTable, "tblNG"
    MsgBox "Information import succefully"


End Sub

after I press the button the vb window opens and this line is highlighted-
Dim destinationRS As New ADODB.Recordset

You might not have included the respective Microsoft ADO Library in references section of your new project.

first of all thank you!!
ok I 'V' the boxes that were 'v' in the working project, in my current project. (in Tools-preferences)..besides one- Microsoft DAO 3.6 object library. when I 'V' it I get error- "Name conflicts with existing module, project, or library."
I don't know where is the conflict..but I tried to run the import anyways and now I get error - path not found.
the same thing happens with the working project but I thought it was because I don't have that file nor that path ( it's just an example file)

but I give it the right path..I even tried few different.. any ideas about that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.