output reports as html files with working hyperlinks
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 214   1
URL.หัวข้อ / URL
output reports as html files with working hyperlinks

มีคนถามคำถามนี้ไว้ที่ http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=32475 
 
ดังนี้ 
 
Hi,  
 
I am building an Access database, that I need to  
use to generate flat (i.e. no ASP or any dynamic server  
hosting available) html files.  
 
The html pages are simple list type view, with records in rows. I need to be able to click a link in each record row and see a  
detail view.  
 
The data will be managed within Access (edited etc), with  
forms, and sub-forms I've made - this all works fine.  
 
I have built 2 reports (list view, detail view) in the format I need for the html pages, and have built an export button to run the  
OutputTo function, and generate the html pages.  
 
All this seems to be working very well, but I cannot  
figure out how to generate the hyperlinks on the list  
view html page, with the necessary (relative) path to the  
correct detail view html page.  
 
Firstly, Access does not seem to let me have any control  
over the full filenames of the html pages it generates,  
they are just '[reportname]Page1.html' , '[reportname]  
Page2.html'...etc  
 
So i tried adding a text box on the report with the value  
set to ="CourseDetailPage" & [CurrentRecord] & ".html" ,  
and set its hyperlink property to true. This looks  
perfect on the report, but when i export to html it's not  
a link, it's just underlined blue text? How can I bind  
this expression to a text box, and have it work as a link  
in the html file?  
 
Using the Insert Hyperlink command doesn't work either  
because, i cannot bind an expression to the hyperlink  
property.  
 
is there a way to create linked pages in flat html files?  
with links auomatically made?  
 
I could easily make the course code number field on the  
report a hyperlink, and it works as a link on the output  
html file, but I have no control over what all the detail  
view pages are called, so they are not named  
course_code.html. Doing a batch rename of all the files  
after the export would not work as the course codes are  
non-sequential 5 digit numbers.  
 
Can anyone help with this problem? I would be very  
appreciative of assistance, I will gladly elaborate if I  
have not explained it well.  
 
thank you 
 
สรุปจากคำถาม สิ่งที่เขาต้องการ คือ สร้าง Text Box แบบ Unbound ในรายงาน เช่น 
="CourseDetailPage" & [CurrentRecord] & ".html" 
เพื่อที่จะบันทึกเป็น HTML ไฟล์ โดยให้ Text Box นั้นเป็น Hyperlink ในไฟล์ HTML ที่ได้สร้างขึ้น 
ทำไม่ได้ ถึงแม้ตอนวิวดูรายงานจะเห็น Text Box ดังกล่าวมีตัวหนังสือเป็นสีน้ำเงิน เหมือนว่าจะเป็น Hyperlink อย่างงั้นแหล่ะ
 
 
ผมได้แนะนำให้เขาเปลี่ยนจากใช้ Text Box ไปใช้ Label แทน เพราะ Label จะมี Hyperlink Address และ Hyperlink SubAddress Properties จึงต้องใช้โค้ดเข้ามาช่วย โดยใช้ On Format ใน Section Detail 
 
แต่ Tricks จะอยู่ตรงที่ ให้สร้าง Label เปล่าขึ้นมาก่อน ตามจำนวนที่ต้องการ โดยในการสร้างแต่ละครั้ง ให้เคาะช่องว่าง 1 เคาะ เพื่อให้ Label นั้นไม่หายไป (ซึ่งมันจะหายไปเมื่อไม่พิมพ์ข้อความอะไรลงไปเลย) หรือจะพิมพ์อะไรลงไปก็ได้  ซึ่งเราจะใช้โค้ดแทนที่มันตอนเปิดรายงานอยู่แล้ว จากตัวอย่างข้างล่าง Label จะชื่อ Label4 
 
จากนั้นก็ใส่โค้ดนี้ลงไป 
 
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)  
Me.Label4.Caption = "My HTML"  
Me.Label4.HyperlinkAddress = "test" & ".html"  
End Sub  
 
จากนั้นก็ให้วิวดูรายงาน ก็จะเห็นว่าตรง Label จะมีข้อความว่า My HTML และมีสีเหมือนกับ Hyperlink ทั่วไป 
 
คราวนี้ลองส่งออกให้เป็นไฟล์ HTML ดูว่าตรง My HTML จะเป็น Hyperlink หรือเปล่า ด้วยการใช้คำสั่ง OutPutTo ดังนี้ 
 
Sub SaveAsHTML() 
     DoCmd.OutputTo acOutputReport, "Report1", acFormatHTML, "c:/test.html" 
End Sub 
 
หมายเหตุ 
โดยปกติ ถ้าเป็น Bound Text Box ที่มีฟีลด์เป็นแบบ Hyperlink มันจะแปลงให้เป็น Hyperlink ในรายงานให้เอง ไม่ต้องเขียนโค้ดให้ยุ่งยากครับ
 
 

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06591
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0519s