• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Error: Method 'Field' of Object '_Recordset' failed

I created a DCOM component. The server Component resides on a Remote machine when I execute the client I am getting an error : Method 'Field' of Object '_Recordset' failed. Part of the Client Code where I am getting the error is given below


 Set adoRecsetServer = New ADODB.Recordset
 'Open ServerContact Table
    With adoRecsetServer
        .Open "ServerContact", adoConn, adOpenKeyset, adLockOptimistic
    End With
    'Get the LastsyncTime from Server
    dtLastServerSyncTime = colAllserverdata.Item(1)
   
    'Get the ServerData to be synchronized
    Set adorecsetCont = New ADODB.Recordset
    Set adorecsetCont = colAllserverdata.Item(2)
   
    'Adding Contact data obtained from server to ServerContact Table Created above
    While Not adorecsetCont.EOF
        adoRecsetServer.AddNew
        For intfldcnt = 0 To adoRecsetServer.Fields.Count - 3
            adoRecsetServer.Fields(intfldcnt).Value = adorecsetCont.Fields(intfldcnt).Value
        Next intfldcnt
        adoRecsetServer.Update
        adorecsetCont.MoveNext
    Wend
    adoRecsetServer.Close
    Set adoRecsetServer = Nothing

I am getting the Error when the Client Data is assigned to Server data.(The Statement in the For loop is causing the error)

In the Above code the adorecsetServer is a recordset for storing the server data into  Access Table at client side

adorecsetCont is the recordset variable in which the server data is existing.
0
gondesiravi
Asked:
gondesiravi
1 Solution
 
hongjunCommented:
Are you trying to do a insertion or update? Since For Loop is executed this means there are records in table. But how come you are trying to insert records on existing records?

hongjun
0
 
Valliappan ANSenior Tech ConsultantCommented:
Does the recordset consist of correct number of fields?

That is adorecsetCont, does it have intfldcnt - pointing number or index for fields?

Just do a check for that.

You could better use the field name, if possible, instead of using the index to do fields value updation. Since, then, even when the fields order is changed in one recordset, it will update the correct field from one recordset to another recordset.

Cheers.
0
 
gondesiraviAuthor Commented:
To Valli

The code which I wrote is working fine if the Client and Server is working on the same system, but if the Server is on Remote machine then I am getting the said error.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Valliappan ANSenior Tech ConsultantCommented:
But, I hope the Remote maching database and Client machine database are different and it is possible to have different structures, right?
0
 
gondesiraviAuthor Commented:
v do not have a data base on the client side!
v have a database on the server side!
the thing is that from the Clients machine v get some records which r to be added to the server's database!
to acheieve that v have taken some temporary tables on the client's side and v have written it in the code such that it will assign the data to these tables.
the structure of the databases however is the same b'coz though there r many fields on the servers database, v have chosen  only some from them and the same is done writing a stored procedure!
but speaking on structure of the databases , yes their structures r different!
is the error occuring b'coz of that?
but then it should give me the error even if i run the client and the server on the machine na?

0
 
Valliappan ANSenior Tech ConsultantCommented:

adoRecsetServer.Fields(intfldcnt).Value = adorecsetCont.Fields(intfldcnt).Value

Before this line, you do this and check if both the fields are the same for Server and Client in both your local client and remote client:

Msgbox "Index: " & intfldcnt & " Server:" & adoRecsetServer.Fields(intfldcnt).Name
Msgbox "Client:" & adorecsetCont.Fields(intfldcnt).Name

Hope this helps.
0
 
gondesiraviAuthor Commented:
When it encounters the statement "adorecsetCont.Fields(intfldcnt)" then it is giving the error "Method Field of Object _Recordset" failed and I am getting this only when the Server is in a Remote machine and is working fine if the server and client are in the same machine.
0
 
Valliappan ANSenior Tech ConsultantCommented:
So, now you got, where your problem is, right? That is for a particular index, field name in Server recordset, that index is not there in the remote client recordset?

So, thats why, can you frame your recordset assigning in this way:

adoRecsetServer.Fields("field1").Value = adorecsetCont.Fields("field1").Value


if this is not possible, do this:

Msgbox adoRecsetServer.Source
Msgbox adoRecsetCont.Source

Check if both of them, give the same fields list.

Or you could also do this to check field wise if the field order in both recordsets are same:

Dim Str1 As String
Str1 = ""
For intfldcnt = 0 to adoRecsetServer.Fields.Count - 1
   Str1 = Str1 & "," & adoRecsetServer.Fields(intfldcnt).Name
Next

Msgbox "Server Fields: " & Str1

Str1 = ""
For intfldcnt = 0 to adoRecsetCont.Fields.Count - 1
   Str1 = Str1 & "," & adoRecsetCont.Fields(intfldcnt).Name
Next

Msgbox "Client Fields: " & Str1

Check if there is a mismatch in the order of the fields, that you are trying to update. If there is a mismatch, then ensure that the fields order is same in both recordsets and then try the same.

Cheers


0
 
DanRollinsCommented:
Hi gondesiravi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept valli_an's comment(s) as an answer.
*** dang! i wish i could award bonus points!

gondesiravi, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now