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