Solved

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

Posted on 2001-06-25
10
352 Views
Last Modified: 2013-11-25
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
Comment
Question by:gondesiravi
10 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6223886
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6223950
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
 
LVL 1

Author Comment

by:gondesiravi
ID: 6223973
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6224015
But, I hope the Remote maching database and Client machine database are different and it is possible to have different structures, right?
0
 
LVL 1

Author Comment

by:gondesiravi
ID: 6224075
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Accepted Solution

by:
Valliappan AN earned 20 total points
ID: 6224160

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
 
LVL 1

Author Comment

by:gondesiravi
ID: 6224274
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6224336
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139790
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
 
LVL 1

Expert Comment

by:Computer101
ID: 7178893
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now