473,883 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert query, table or SQL to web forum compatible markup

2,322 Recognized Expert Moderator Top Contributor

This article will illustrate how you can convert the contents of a query or a table into BBCode used for many online forums.

I will admit to being a bit professionally damaged, I use Access and VBA for everything now-a-days. If any information needs to be organized in any way, I start by creating a database and whipping away until I have automated the process. Yesterday I needed to take some information from my database and post it to a webforum. However I can't simply copy-paste it, as I need to add in all the formatting. So I quickly decided to make a procedure that could take a query, table, or even a SQL string and convert it into valid code for posting in a forum.

This is the result:
Expand|Select|Wrap|Line Numbers
  1. Public Function ConvertQueryToBB(strSource As String, Optional bIncludeHeaders As Boolean = True) As String
  2. On Error GoTo errHandler
  3.    Dim rs As DAO.Recordset
  4.    Dim strTable As String
  5.    Dim iField As Integer
  6.    Dim strHeaderCellStart As String
  7.    Dim strHeaderCellEnd As String
  8.    strHeaderCellStart = "[td][size=12pt][b][color=blue]"
  9.    strHeaderCellEnd = "[/color][/b][/size][/td]"
  11.    Dim strCellStart As String
  12.    Dim strCellEnd As String
  13.    strCellStart = "[td]"
  14.    strCellEnd = "[/td]"
  16.    Set rs = CurrentDb.OpenRecordset(strSource, dbOpenDynaset, dbReadOnly)
  18.    'Start table
  19.       strTable = "[table]" & vbNewLine
  21.    'Optionally include row headers
  22.       If bIncludeHeaders Then
  23.          strTable = strTable & "[tr]"
  24.          For iField = 0 To rs.Fields.Count - 1
  25.          strTable = strTable & strHeaderCellStart & rs.Fields(iField).Name & strHeaderCellEnd
  26.          Next
  27.          strTable = strTable & "[/tr]"
  29.       End If
  31.    'Loop through recordset adding fields
  32.       Do While Not rs.EOF
  33.          strTable = strTable & "[tr]"
  34.          For iField = 0 To rs.Fields.Count - 1
  35.             strTable = strTable & strCellStart & rs.Fields(iField) & strCellEnd
  36.          Next
  37.          strTable = strTable & "[/tr]"
  40.          rs.MoveNext
  41.       Loop
  43.    'Close table
  44.       strTable = strTable & "[/table]"
  46.    'return string
  47.       ConvertQueryToBB = strTable
  49. exitFunction:
  50.    If Not rs Is Nothing Then rs.Close
  51.    Set rs = Nothing
  52.    Exit Function
  55. errHandler:
  56.    MsgBox Err.Number & " - " & Err.Description
  57.    Resume exitFunction
  58. End Function
Example Calling:
Expand|Select|Wrap|Line Numbers
  1. ConvertQueryToBB("TableName")
  2. ConvertQueryToBB("TableName",False)
  3. ConvertQueryToBB("QueryName")
  4. ConvertQueryToBB("SELECT * FROM tbl_Users Where bAdmin=True ORDER BY FirstName")
Example result in forum:

As always, feel free to like, comment, share, and use the code posted.
Attached Images
File Type: jpg Example.jpg (37.0 KB, 1702 views)
Aug 29 '12 #1
0 25329

Sign in to post your reply or Sign up for a free account.

Similar topics

by: TomT | last post by:
As per subject... Does anyone know how to convert a Toast 1.6 forum (ASP) to a php based forum like phpbb2 ?? The current forum has 280+ members, and 0000's of posts... Thanks
by: dummie_q | last post by:
Hey, I am having some confusion about how to formulate this particular query. I have 2 tables. Table A has 4 columns say a1,a2,a3,a4 with the columns a1,a2,a4 forming the primary key. Table B again has 3 columns with b1,b2,b3,b4 and like before, b1,b2 and b4 form the primary key. All columns are of the same datatype in both tables. Now I want to get rows from table A which are not present in table B. Whats the best way of doing this?
by: patrickdrd | last post by:
Hi all! Does anyone know of any such tool? What I want is: specify a database table (SQL Server) and let the tool convert that table to an asp.net class (automatic generation of properties, methods, etc.) Thanks in advance!
by: sansann | last post by:
Hello there! i need help on loading data from my Access database query table name combine into my MSFlexgrid select by batchno category. when i runn below coding the error said "Selected collating sequence not supported by operating system" Private Sub Command1_Click() Dim search As String Dim index As Integer search = keybatch.Text
by: phil.swenson | last post by:
I'm using Prototype.js and would like to convert the contents of an HTML table to JSON. Converting to an array first is fine too. Any thoughts on this? I haven't seen anyone do anything this.... thanks phil
by: rob | last post by:
Hi Everyone, I am using managed c++ to convert hash table to insert sql statement. Anyone has experience using some class to do it? database: sql anywhere 9.02 Thanks, Robert
by: dilyskam | last post by:
HI ALL, sql-How to convert a table data into XML. PLS. HELP!!!!!
by: bobh | last post by:
Hi All, I have this query which updates a field based on the result of an IIF statement. The table is on SQLServer and I'm linked to it and it has many records and will take Access a very long time to run so I'm thinking I can make this query a pass-thru query and I hope someone can write the proper SQLServer SQL for this Access SQL I know I have to change the IIF to Case When Else but I haven't been able to get it figured out yet.
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >= current date. Otherwise, user have to waste time to page up the pages to find the current date 2. I got a script of simple calendar from the web that use mktime() to create links on the calendar Task I need to let user view data earlier than...
by: Joey | last post by:
I am querying a DataSet with LINQ. I am running into a problem when trying to construct my query because in the "from" clause I do not know the table name (range variable) until runtime. Possible table names might include "SomeTable1" or "SomeTable236" etc... Unfortunately when I try to use something like "from SomeTable + MyChangingNumber.ToString() in..." in my from clause it does not work. How can I set this up to use a range variable...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.