My Assistant
|
|
May 6 2012, 02:05 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 259 |
Hi All,
I have written a function to stream text files to my hard drive. I also have a command button on my form that opens a query as a recordset and replaces some strings in the text stream with data from fields in my query before writing the stream to the hard drive. It is supposed to stream one file for each record in the recordset. I know the recordset is being openned and I know the function is working correctly because I was able to stream a "non replaced" text file but when I use the command button code I am getting an error 2465 "...can't find the field"|" referred to in your expression." Can someone please help me figure out what I am doing wrong here? I posted the command button code and I will be happy to post the function code if anyone wants me to. Thanks in advance for any help. Ken Here is the command button code: CODE Private Sub cmdMakeXMLs_Click()
On Error GoTo Err_MakeXMLs_Click Dim strXML As String Dim fso As New Scripting.FileSystemObject Dim ts As Scripting.TextStream Dim sFile As FileDialog ' Windows File browser Dim Selection As String Dim rs As DAO.Recordset Dim xmlQuery As String xmlQuery = "qryMetadata" Set rs = CurrentDb.OpenRecordset(xmlQuery) ' Set variable Set sFile = Application.FileDialog(msoFileDialogFolderPicker) ' Open and check for CANCEL With sFile .AllowMultiSelect = False If .Show <> -1 Then Exit Sub End If End With ' Store full path Selection = sFile.SelectedItems(1) 'Pass to functions which build XML strings, and store the returned strings With rs Do While Not .EOF strXML = HDxml() strXML = Replace(strXML, "xmlCurrentDate", Format(Date, "yyyy - mm - dd")) strXML = Replace(strXML, "xmlHD_AssetName", [HD_AssetName]) strXML = Replace(strXML, "xmlHD_PackageAsset", [HD_PackageAsset]) strXML = Replace(strXML, "xmlHD_MovieAsset", [HD_MovieAsset]) strXML = Replace(strXML, "xmlHD_PosterAsset", [HD_PosterAsset]) strXML = Replace(strXML, "xmlHD_TitleAsset", [HD_TitleAsset]) strXML = Replace(strXML, "xmlTitleSort", [TitleSort]) strXML = Replace(strXML, "xmlTitleBrief", [TitleBrief]) strXML = Replace(strXML, "xmlTitleDisplay", [TitleDisplay]) strXML = Replace(strXML, "xmlSummary", [Summary]) strXML = Replace(strXML, "xmlRating", [Rating]) strXML = Replace(strXML, "xmlCaptions", [Captions]) strXML = Replace(strXML, "xmlRunTime", [RunTime]) strXML = Replace(strXML, "xmlDisplayTime", [DisplayTime]) strXML = Replace(strXML, "xmlReleasedYear", [ReleasedYear]) strXML = Replace(strXML, "xmlCategory", [Category]) strXML = Replace(strXML, "xmlGenre", [Genre]) strXML = Replace(strXML, "xmlStartDate", [StartDate]) strXML = Replace(strXML, "xmlEndDate", [EndDate]) 'open the XML file with the name specified in the variable HD_AssetName. Set ts = fso.OpenTextFile(Selection & [HD_AssetName] & ".xml", ForWriting, True) 'with the file open, write the xml text stream to it ts.Write strXML 'close the text stream object ts.Close Set ts = Nothing 'Verify that the file was written successfully and send an alert if it was not If Not fso.FileExists(Selection & [HD_AssetName] & ".xml") Then MsgBox "There was an error creating " & [HD_AssetName] & ".xml" & ".", vbOKOnly End If .MoveNext Loop .Close End With ' Release variable Set sFile = Nothing Exit_MakeXMLs_Click: Exit Sub Err_MakeXMLs_Click: MsgBox "MakeXMLs_Click Error# " & Err.Number & " - " & Err.Description End Sub |
|
|
|
![]() |
May 7 2012, 12:53 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 23,583 From: Mississippi |
You're welcome, Ken. I am glad I could help.
The other way is considerably harder believe me. I involves setting the parameters in the code window, like this: Set qdef = db.Queries("NameOfQuery") qdef.Parameters(0).[Forms!NameOfForm!NameOfControl] = [Forms]![NameOfForm]![NameOfControl] etc. until all parameters defined. I used to to it like the above, then I discovered the Eval function. Much easier, it goes and gets the value from the form control, then places that into your query. |
|
|
|
madmix Need Help Streaming A Text File From A Query Recordset May 6 2012, 02:05 PM
bulsatar The thing that I notice is that the calling of the... May 6 2012, 02:35 PM
madmix Hi bulsatar,
That was it. Thanks! I am stil... May 6 2012, 04:37 PM
bulsatar A couple of things...might try and concact the str... May 6 2012, 04:58 PM
madmix Yes it hit me a few seconds ago that this is what ... May 6 2012, 05:02 PM
madmix That was it... I forgot the trailing slash. Thank... May 6 2012, 07:54 PM
fkegley The code window does not always understand paramet... May 7 2012, 09:12 AM
madmix Hi Frank,
Thanks for your advice. I tried the ev... May 7 2012, 11:00 AM![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 24th May 2013 - 10:41 PM |