PC Review


Reply
Thread Tools Rate Thread

Bind Form to XML source

 
 
PANCZO via AccessMonster.com
Guest
Posts: n/a
 
      2nd Jul 2005
HI!

I have a problem...
I try to bind XML data to (unbound) form
so, on Load:

Dim rst As New ADODB.Recordset
On Error Resume Next
rst.Open "pathtomyxmlfile", "Provider=MSPersist;", , , adCmdFile

If Err.Number = 0 Then
Set me.recordset = rst
End If


And I see data on the form (I cut code with sets controlsource)
, but I can't modyfy and add new records.
Any solutions?

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
Pat Hartman
Guest
Posts: n/a
 
      3rd Jul 2005
XML isn't a direct access file. It is a flat file. It would be treated as
a .txt file would be treated and you can't update those either.
"PANCZO via AccessMonster.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> HI!
>
> I have a problem...
> I try to bind XML data to (unbound) form
> so, on Load:
>
> Dim rst As New ADODB.Recordset
> On Error Resume Next
> rst.Open "pathtomyxmlfile", "Provider=MSPersist;", , , adCmdFile
>
> If Err.Number = 0 Then
> Set me.recordset = rst
> End If
>
>
> And I see data on the form (I cut code with sets controlsource)
> , but I can't modyfy and add new records.
> Any solutions?
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      3rd Jul 2005
If this is Access 2000, that's a limitation of the Recordset property in
Access 2000, the form will always be read-only. In later versions of Access
the form can be read/write, but you must set the CursorLocation, CursorType
and LockType properties of the recordset - as always when opening an ADO
recordset, if you accept the default values for these properties you get a
read-only, forward-only recordset. Here's an example ...

Option Compare Database
Option Explicit

Dim mrst As ADODB.Recordset

Private Sub cmdLoad_Click()

Set mrst = New ADODB.Recordset
With mrst
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open CurrentProject.Path & "\test.xml", , , , adCmdFile
End With

Set Me.Recordset = mrst

End Sub

Private Sub cmdSave_Click()

mrst.Save

End Sub

Private Sub Form_Close()

If Not mrst Is Nothing Then
If mrst.State <> adStateClosed Then
mrst.Close
End If
End If

End Sub

--
Brendan Reynolds (MVP)

"PANCZO via AccessMonster.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> HI!
>
> I have a problem...
> I try to bind XML data to (unbound) form
> so, on Load:
>
> Dim rst As New ADODB.Recordset
> On Error Resume Next
> rst.Open "pathtomyxmlfile", "Provider=MSPersist;", , , adCmdFile
>
> If Err.Number = 0 Then
> Set me.recordset = rst
> End If
>
>
> And I see data on the form (I cut code with sets controlsource)
> , but I can't modyfy and add new records.
> Any solutions?
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
PANCZO via AccessMonster.com
Guest
Posts: n/a
 
      3rd Jul 2005
Thanks Bernard!

I can modify, but I still "fight" with add new record on the form...
It is possible that me idea is not got, but I write application (as .adp)
in Access 2003, and this solutions I think is neccessery.
I try explain:
So, when user want for example edit invoice, I connect to SQL Server get the
data and give user posibility to edit. Simple...
But sometimes the invoice have a ca. 1000 lines, and user make this a few
houres. and somtimes power faliure or connection lose, so I decied to give
him local source. So, when users get invoice I seve recordset to xml, and
wbind data from file to form, and time to taime, app save the updated
recordset to xml.

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      3rd Jul 2005
It's Brendan, not Bernard.

This seems to work ...

Private Sub cmdNew_Click()

Me.Recordset.AddNew

End Sub

I can't comment on whether this is a good approach or not, an invoice with
1000 items is something outside of my experience.

--
Brendan Reynolds (MVP)

"PANCZO via AccessMonster.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks Bernard!
>
> I can modify, but I still "fight" with add new record on the form...
> It is possible that me idea is not got, but I write application (as .adp)
> in Access 2003, and this solutions I think is neccessery.
> I try explain:
> So, when user want for example edit invoice, I connect to SQL Server get
> the
> data and give user posibility to edit. Simple...
> But sometimes the invoice have a ca. 1000 lines, and user make this a few
> houres. and somtimes power faliure or connection lose, so I decied to give
> him local source. So, when users get invoice I seve recordset to xml, and
> wbind data from file to form, and time to taime, app save the updated
> recordset to xml.
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
PANCZO via AccessMonster.com
Guest
Posts: n/a
 
      3rd Jul 2005
Tahnks for all!

Full code from my "testform"
=================================================================
Option Compare Database
Option Explicit

Dim mrst As ADODB.Recordset

Private Sub cmdSave_Click()
mrst.Save , adPersistXML
End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
mrst.AddNew
mrst.Save , adPersistXML
mrst.MoveLast
End Sub

Private Sub Form_Close()
If Not mrst Is Nothing Then
If mrst.State <> adStateClosed Then
mrst.Close
End If
End If
End Sub

Private Sub Form_Load()
Set mrst = New ADODB.Recordset
With mrst
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open CurrentProject.Path & "\test.xml", , , , adCmdFile
End With
Set Me.Recordset = mrst
End Sub
=================================================================

Now, I can everything (update,insert, delete).
If enybody now better solution for my idea, I heve "open mide"

Best regards
Michal

P.S. sorry for my english

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does databinding affect the source data used to bind to the control? mark4asp Microsoft ASP .NET 1 6th Jul 2007 04:58 PM
How to bind the same source object in two forms without synchroniz =?Utf-8?B?U3lsdmFpbg==?= Microsoft Dot NET Framework Forms 2 12th Nov 2004 02:03 PM
Bind Checkbox to a data source ? JezB Microsoft Dot NET Framework Forms 1 2nd Apr 2004 05:01 PM
Bind dropdownlist to differnt data source than the DataGrid =?Utf-8?B?RGVyZWs=?= Microsoft Dot NET 0 17th Mar 2004 04:01 AM
Event ID 115, Source W3SVC. The service could not bind instance 3. Pam Microsoft Windows 2000 0 15th Oct 2003 04:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.