Solved

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

Posted on 2001-06-25
10
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 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