• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Creating an asp page in access 2000

I want to create an asp page in my website using vba.
Do do that, I use a stream object and then use the following instruction:
       streamObject.writetext string
The program wotks well except for 1 thing:
      It writes the asp page in unicode and the browser cannot open an asp page with unicode characters.
Anobody knows how to get around that?

THANKS
0
Gite
Asked:
Gite
  • 7
  • 3
1 Solution
 
Alan WarrenCommented:
Hi Gite,

I expect you are using the FilesytemObject to create your ASP file and populate with the contents of your stream.
The CreateTextFile Method of the filesystem object has a boolean parameter for unicode, you need to set this to False

object.CreateTextFile(filename[, overwrite[, unicode]])

unicode Optional.
Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is True if the file is created as a Unicode file; False if it's created as an ASCII file. If omitted, an ASCII file is assumed.

objFso.CreateTextFile strPath, True, False
Set objFile = objFso.GetFile(strPath)


Alan





0
 
Alan WarrenCommented:
Hi Gite,

this works...


Option Explicit

Public Sub somesub()
 
  ' Reference:
  ' Microsoft Scripting Runtime
  ' Microsoft AciveX Data Objects 2.6 Lib
 
  Dim objFso As Scripting.FileSystemObject
  Dim objStream As Stream
  Dim strPath As String
 
  strPath = CurrentProject.Path & "\Test.asp"
 
  Set objFso = New Scripting.FileSystemObject
 
  objFso.CreateTextFile strPath, True, False
 
  Set objStream = New ADODB.Stream
 
  With objStream
    .Type = adTypeText
    .Open
    .WriteText "<%@ Language=VBScript %><HTML><HEAD></HEAD><BODY>test</BODY></HTML>"
    .SaveToFile strPath, adSaveCreateOverWrite
    .Close
  End With
  Set objStream = Nothing
  Set objFso = Nothing


End Sub


Alan
0
 
GiteAuthor Commented:
Can't get it to work. Here is a simplified version of my code:
    Const sStartPage = "<%Session.abandon %><HTML><HEAD>" & _
            "<TITLE>title</TITLE></HEAD><BODY>"
    Const sEndPage = "</BODY></HTML>"
    Const sStartLink = "<A href=""http://yourfolks.com"">"
    Const sEndLink = " family</A> "
    Dim objFso
    Dim strPage As Stream
    Set objFso = CreateObject("Scripting.FileSystemObject")
    objFsoAn.CreateTextFile "c:\inetpub\wwwroot\yourfolks\Families.asp", True, False
    Set strPage = New Stream    strPageFr.Type = adTypeText: strPageAn.Type = adTypeText
    strPage.Open
    strPage.WriteText sStartPage
    Set db = CurrentDb
    Set rst = db.OpenRecordset("qyFamilies", dbOpenForwardOnly)
    With rst
        While Not .EOF
            strPage.WriteText sStartLink & !Segment & sEndLink
            .MoveNext
        Wend
        .Close
    End With
    strPage.WriteText sEndPage
    strPage.SaveToFile "c:\inetpub\wwwroot\mesaieux\Families.asp", adSaveCreateOverWrite
    strPage.Close
    Set strPage = Nothing
    Set objFso = Nothing
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Alan WarrenCommented:
Hi Gite,

suggest you use a temp string variable, to construct your html then before you write it to your asp page use
and have a look at the output in the immediate window


Dim strTemp as String
' build your html
Debug.Print strTemp
' If html looks good instantiate the stream and the file object, and parse the strTemp to the file body.





This line looks suspect
Set strPage = New Stream    strPageFr.Type = adTypeText: strPageAn.Type = adTypeText
maybe:
Set strPage = New Stream: strPageFr.Type = adTypeText: strPageAn.Type = adTypeText

also:
strPageFr and strPageAn are not declared or used.

At no point are you setting the .Type property  for strPage


take care...


Alan


0
 
Alan WarrenCommented:
Hi Gite,


' Force Explicit declaration of variables by declaring
' Option Explicit at the top of all code modules
' before any subs or functions or module scope variables or constants
Option Explicit    ' <<< this is a good idea

Public Sub somesub2()

  ' References:
  ' Microsoft Scripting Runtime
  ' Microsoft AciveX Data Objects 2.6 Lib
  ' ------------------------------^------ first version of ADO to support Streaming
  ' Microsoft DAO Objects Lib 3.6
 
On Error GoTo ReportError
 
    Const sStartPage = "<%@ Language=VBScript %><%Session.abandon %><HTML><HEAD>" & _
            "<TITLE>title</TITLE></HEAD><BODY>"
    Const sEndPage = "</BODY></HTML>"
    Const sStartLink = "<A href= 'http://yourfolks.com'>"
    Const sEndLink = " family</A><br /> "
   
    Dim objFso As Scripting.FileSystemObject
    Dim objStream As Stream
   
    Dim objDB As DAO.Database
    Dim objRS As DAO.Recordset
   
    Dim strTemp As String
   
    strTemp = sStartPage
   
    Set objDB = CurrentDb
    Set objRS = objDB.OpenRecordset("qyFamilies", dbOpenForwardOnly)
    With objRS
      While Not .EOF
        strTemp = strTemp & sStartLink & !Segment & sEndLink
        .MoveNext
      Wend
      .Close
    End With
   
    strTemp = strTemp & sEndPage
    Debug.Print strTemp
   
    ' stop code and view output in immediate window,
    ' maybe even manually paste it into an asp page, see how it flies.
    Stop  ' << dont forget to remove this after debugging
   
   
    ' once you know you have the structure correct automate the file creation.
    Set objFso = New Scripting.FileSystemObject
    objFso.CreateTextFile "c:\inetpub\wwwroot\yourfolks\Families.asp", True, False
   
   
    Set objStream = New ADODB.Stream
    With objStream
      .Type = adTypeText
      .Open
      ' Write the temp STRING to the OBJECT stream
      .WriteText strTemp
      .SaveToFile "c:\inetpub\wwwroot\mesaieux\Families.asp", adSaveCreateOverWrite
      .Close
    End With
   

ExitProcedure:
  On Error Resume Next
 
  DoCmd.Hourglass False
  DoCmd.SetWarnings True
 
' Destroy instantiated objects
  Set objRS = Nothing
  Set objDB = Nothing
  Set objStream = Nothing
  Set objFso = Nothing

  Exit Sub

ReportError:
 
  Select Case Err.Number
    Case Else
      Dim strMsgText As String
      strMsgText = "Error in somesub2()" _
        & vbCr & "Error number " & CStr(Err.Number) _
        & " was generated by " & Err.Source _
        & vbCr & Err.Description
      MsgBox strMsgText, vbExclamation + vbMsgBoxHelpButton, "Error", Err.HelpFile, Err.HelpContext
  End Select
  Resume ExitProcedure
   
End Sub


Take care...


Alan
0
 
GiteAuthor Commented:
I always use EXPLICIT. I also use Microsoft AciveX Data Objects 2.6 Lib.

In fact, I should have told you the code I submitted to you works correctly except for unicode: when I see the code it generates in the asp page, everything is OK. However, when I open the asp page in my browser (IE6), I get the following message:
     Pages ASP error 'ASP 0239'
     Cannot process file
    /yourfolks/Families.asp, line 1
     UNICODE ASP files are not supported

So, I conclude that the instruction
     objFso.CreateTextFile "c:\inetpub\wwwroot\yourfolks\Families.asp", True, False
didn't do what it is supposed to do (generate ascii text) and my asp page was generated in Unicode.

What do you think?
0
 
Alan WarrenCommented:
Hi Gite,


Re:
So, I conclude that the instruction
     objFso.CreateTextFile "c:\inetpub\wwwroot\yourfolks\Families.asp", True, False
didn't do what it is supposed to do (generate ascii text) and my asp page was generated in Unicode.
================================================================
There is an easy test for this, unicode file should be larger.
If i run these two lines of code then halt execution and check the file size, one is 0 bytes and one is 2 bytes
  objFso.CreateTextFile strPathAsc, True, False
  objFso.CreateTextFile strPathUni, True, True
  STOP

TestUni.asp
2 bytes

TestAsc.asp
0 bytes

I am sure it is creating a Unicode file, but I expect that the .WriteText method of the stream object is mucking it up some how.
==================================================================


Currently looking at the Charset Property of the ADO.Stream
ADO API Reference  
Charset Property
Indicates the character set into which the contents of a text Stream should be translated.

Settings and Return Values
Sets or returns a String value that specifies the character set into which the contents of the Stream will be translated. The default value is "Unicode". Allowed values are typical strings passed over the interface as Internet character set strings (for example, "iso-8859-1", "Windows-1252", etc.). For a list of the character set strings that is known by a system, see the subkeys of HKEY_CLASSES_ROOT\MIME\Database\Charset in the Windows Registry.

Remarks
In a text Stream object, text data is stored as Unicode. The Charset property translates the data read from the Stream into the specified character set. Similarly, data written to the Stream in the specified character set is translated into Unicode for storage in the Stream object.


Alan



0
 
Alan WarrenCommented:
Hi Gite,

try setting the Charset property of the stream object to "ascii"

  With objStream
    .Charset = "ascii"
    .Type = adTypeText
    .Open
    .WriteText "<%@ Language=VBScript %><HTML><HEAD></HEAD><BODY>test</BODY></HTML>"
    .SaveToFile strPathAsc, adSaveCreateOverWrite
    '.SaveToFile strPathUni, adSaveCreateOverWrite
    .Close
  End With
  Set objStream = Nothing


Alan
0
 
GiteAuthor Commented:
Problem solved. Thanks
0
 
Alan WarrenCommented:
Excellent news!

thanks for the question, it was fun.
I actually do a fair bit of this kind of thing in my Access apps, creating a web on first run of the app, the web being used as online help for the custom application, but I have never encountered that error before.

take care...


Alan

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now