A problem reading a file


E

ericb

I'm having a problem reading a file.

The file to read has been stored as an XML file. In that file is only 1 and
always only 1 record of a table.

It was stored in the file this way :

'---------------------------------
public StoreTableTrans(strFile, strTableCmd, as String)

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
Set myRecordSet.ActiveConnection = cnn1

Dim mySQL As String


' Transfert la table dans un fichier
mySQL = "SELECT * FROM [" & strTableCmd & "]"
mySQL = mySQL + " WHERE [" & strTableCmd & "].ID_cmd = 1"
myRecordSet.Open mySQL, cnn1, adOpenDynamic, adLockOptimistic

myRecordSet.Save strfile, adPersistXML

myRecordSet.Close
cnn1.Close
Set myRecordSet = Nothing
Set cnn1 = Nothing

StoreTableTransmission = strfile

End Function
'---------------------------------

After that, when I open the file with an editor everything seems to be in
order.

My problem is to read it back.

This is what i'm doing :

'---------------------------------
Public Sub LireFichierCmd(strFichierCmd As String)

Dim cnn1 As New ADODB.Connection
Dim myRecordSet As ADODB.Recordset

' Transfert la table dans un fichier
Set myRecordSet = New ADODB.Recordset
myRecordSet.Open strFichierCmd, "Provider=MSPersist;",
adOpenForwardOnly, adLockBatchOptimistic, adCmdFile
MsgBox "nomclient = " & myRecordSet!nom_client

cnn1 = CurrentProject.Connection
myRecordSet.ActiveConnection = cnn1
myRecordSet.UpdateBatch

' Clean up
myRecordSet.Close
cnn1.Close
Set myRecordSet = Nothing
Set cnn1 = Nothing


End Sub
'---------------------------------

when I print "nom_client = " i'm getting "& str &" which is wrong and then i
get the message : the connection cannot be used ...

This function is called by clicking a cmd button on FormA. On FormA is
SubformB. The SubformB is a datasheet that shows the containts of
myTable to which myRecordSet is to be connected.

My objective is to add a new record to myTable and the data for the new
record is to be read from the file strFichierCmd.

Where am i going wrong ?

The help is appreciated

Thank you
 
Ad

Advertisements

H

Hans Up

ericb said:
My objective is to add a new record to myTable and the data for the new
record is to be read from the file strFichierCmd.

Where am i going wrong ?

When I wanted to import XML, I used a simpler approach.

Application.ImportXML strFichierCmd, acAppendData

I don't know if that will work with your XML file. It does seem to work
reliably with XML files created by the Application.ExportXML method.
 
Ad

Advertisements

W

walter compton

ericb said:
I'm having a problem reading a file.

The file to read has been stored as an XML file. In that file is only 1
and
always only 1 record of a table.

It was stored in the file this way :

'---------------------------------
public StoreTableTrans(strFile, strTableCmd, as String)

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
Set myRecordSet.ActiveConnection = cnn1

Dim mySQL As String


' Transfert la table dans un fichier
mySQL = "SELECT * FROM [" & strTableCmd & "]"
mySQL = mySQL + " WHERE [" & strTableCmd & "].ID_cmd = 1"
myRecordSet.Open mySQL, cnn1, adOpenDynamic, adLockOptimistic

myRecordSet.Save strfile, adPersistXML

myRecordSet.Close
cnn1.Close
Set myRecordSet = Nothing
Set cnn1 = Nothing

StoreTableTransmission = strfile

End Function
'---------------------------------

After that, when I open the file with an editor everything seems to be in
order.

My problem is to read it back.

This is what i'm doing :

'---------------------------------
Public Sub LireFichierCmd(strFichierCmd As String)

Dim cnn1 As New ADODB.Connection
Dim myRecordSet As ADODB.Recordset

' Transfert la table dans un fichier
Set myRecordSet = New ADODB.Recordset
myRecordSet.Open strFichierCmd, "Provider=MSPersist;",
adOpenForwardOnly, adLockBatchOptimistic, adCmdFile
MsgBox "nomclient = " & myRecordSet!nom_client

cnn1 = CurrentProject.Connection
myRecordSet.ActiveConnection = cnn1
myRecordSet.UpdateBatch

' Clean up
myRecordSet.Close
cnn1.Close
Set myRecordSet = Nothing
Set cnn1 = Nothing


End Sub
'---------------------------------

when I print "nom_client = " i'm getting "& str &" which is wrong and then
i
get the message : the connection cannot be used ...

This function is called by clicking a cmd button on FormA. On FormA is
SubformB. The SubformB is a datasheet that shows the containts of
myTable to which myRecordSet is to be connected.

My objective is to add a new record to myTable and the data for the new
record is to be read from the file strFichierCmd.

Where am i going wrong ?

The help is appreciated

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top