MS Access underline text in a Table - ms-access-2013

I have long Text field in a table in MS ACCESS. I need to underline it for specific text in a field. I tried to change Text format to Rich Text in the design view , but I am getting:
Error : Operation is not supported for this type of Object
In the table I have 320 rows. I need to Underline for N.J.S.A. only in the long text.
Please help me regarding this. Thanks in Advance

Well... you have to get that field property changed from plain text to rich text for this to work and design view should handle this. If not try the below code.
Public Sub TestUnderline()
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strString As String
Set db = CurrentDb
Set tbl = db.TableDefs("Table1") 'Change to your table name
Set fld = tbl.Fields("TestField") 'Change to your field name
With fld.Properties("TextFormat")
If .Value = acTextFormatPlain Then
.Value = acTextFormatHTMLRichText
End If
End With
strSQL = "SELECT TestField " & _ 'Change to your Field name
"FROM Table1;" 'Change to your table name
Set rst = db.OpenRecordset(strSQL)
Do While Not rst.EOF
If InStr(1, rst![TestField], "N.J.S.A") Then 'Change to your field name
strString = Replace(rst![TestField], "N.J.S.A", "<u>N.J.S.A</u>") 'Change to your field name
rst.Edit
rst![TestField] = strString 'Change to your field name
rst.Update
End If
rst.MoveNext
Loop
EndCode:
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not tbl Is Nothing Then
Set tbl = Nothing
End If
If Not db Is Nothing Then
Set db = Nothing
End If
End Sub
Credit given to:
How to convert a text field in an Access table to a rich text memo using VBA
and:
http://www.tek-tips.com/viewthread.cfm?qid=1538917

Related

FILTER OLAP CUBE WITH VBA

I am trying to update an OLAP pivotfilter with the value of another cell (not in a pivot table).
The code I have is as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when
'cell C1 or C2 is touched
If Intersect(Target, Range("C1:C2")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewStock As String
'Here you amend to suit your data
Set pt = ActiveSheet.PivotTables("PivotFilter")
'The activesheet is named "Top1_Value"
Set Field = pt.PivotFields("[StockCode].[Stock Code_SKU].[Stock Code_SKU]")
NewStock = ActiveSheet.Range("C1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.VisibleItemsList = NewStock
pt.RefreshTable
End With
End Sub
Any assistance to resolve would be appreciated.

How to populate data in combo box from sql server

I have a combo box name cbSection
how can i populate the data from sql server in combo box ?
Any idea will help
-Thanks
This is direct from VbForums (I take no credit for the code!), first result for a quick Google search.
Dim strSQL as String 'Declare the variables we need
Dim oRS as ADODB.Recordset
Set oRS = New ADODB.Recordset
'Load the data
'** change this SQL to load the data you want.
strSQL = "SELECT Colour FROM Colours"
'** change oConn to the name of your Connection object
oRS.Open strSQL, oConn, adOpenForwardOnly, adLockReadOnly, adCmdText
'Fill the combo box (or ListBox)
'** change the name of the combo to the one you want to fill
With cboColour
.Clear
Do While Not oRS.EOF
'** change the name of the field here to the one you want to show
.AddItem oRS.fields("Colour").value
oRS.MoveNext
Loop
End With
'Tidy up
oRS.Close
Set oRS = Nothing

Classic ASP Iterate through and Object

I'm a PHP developer, learning ASP.
I've become very reliant on PHP's useful functions: print_r() and var_dump() to see what an array or object contains.
I don't always know what columns are in a Db Table. So, when a SELECT * From Tbl is queried, and the objRS is populated, would I be able to view what the entire object's contents are?
Is this possible in ASP?
<% `my simple Select statement
Dim strDbConnection
Dim objConn
Dim objRS
Dim strSQL
strDbConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test.mdb;"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(strDbConnection)
strSQL = "SELECT * FROM persons"
Set objRS = objConn.Execute(strSQL)
If objRS.EOF Then
Response.Write("No items found")
Else
Do While Not objRS.EOF
' show all columns I can extract here....
objRS.MoveNext()
Loop
End If
objRS.Close()
Set objRS = Nothing
objConn.Close()
Set objConn = Nothing
%>
-- I would like to see what's coming back at me in the objRS, and then cherry-pick the columns after I know what I have access to.
Is there something similar to what I'm used to?
ie: print_r()
You can use objRS.fileds(j).name and objRS.fields(j).value to get the name of columns and values.
For example:
[...]
for j = 0 to objRS.fields.count - 1
response.write(objRS.fields(j).name & " = " & objRS.fields(j).value)
next

How can I create datareport using recordset in vb6?

Private Sub showreport_Click()
sql = "select * from student_record_database where"
sql=sql+ Grade='" & Combo1.Text & "' AND Meal='" & Combo11.Text & "'"
Set RES = CON.Execute(sql)
Set DataReport1.DataSource = RES
DataReport1.WindowState = vbMaximized
DataReport1.Show vbModal
End Sub
I am using this code as record set to create a data report.
My task is to choose options from various combo boxes and then display it's report so record set is needed there..
My question is that whether this code is sufficient to create data report???
I didn't set any properties of data environment or data report such as (connection - command - sql) because I am passing this record set directly to data report,then no need to fire any sql in properties of data environment.
But unfortunately it is not showing desired output
Please help me.
Try this one:
Private sub cmdprint_click()
Dim rs as new adodb.recordset
rs.open "SQL Query Statement Here",CON, adOpenDynamic, adLockOptimistic
set datareport1.datasource=rs
datareport1.show
end sub
Notes:
The data report datasouce should be cleared during design mode. (See properties on the datareport and set its datasource property to empty.) Ohhh...one more thing, please keep in mind that you should set also the datafield property for each textbox object inside the datareport corresponding to the datafield on your database during design time...
I am using this method for a long time and it works fine.
Try this.
To add a quite to a string, use a double quite.
Also you missed spelled the second Combo1 reference as Combo11
Private Sub showreport_Click()
sql = "select * from student_record_database where "
sql = sql & "Grade=""" & Combo1.Text & """ AND Meal=""" & Combo1.Text & """"
Set RES = CON.Execute(sql)
Set DataReport1.DataSource = RES
DataReport1.WindowState = vbMaximized
DataReport1.Show vbModal
End Sub

How to add column to FoxPro file using DAO

I need to add some columns to a FoxPro 2.6 DBF file using DAO in VB6.
If the data were in an .MDB file, I know this would work. Here is a code snippet which I use for .MDB:
Set tdfCoParms = mDBParms.TableDefs(CoParms)
tdfCoParms.Fields.Append tdfCoParms.CreateField("CoName", dbText, 30)
Am unsure if this works for FoxPro. (I have not tried)
Is this possible? There is a possible alternative - which I know would work, but which is not so convenient - by starting with an empty table of the correct structure, then copying across the records from the existing populated file, using INSERT of a SELECT from this.
Thank you #wqw, as your solution certainly works.
This was my first alternative, which worked:
Create an empty file/table with the desired columns.
Copy this file to "test.dbf".
Insert records from the populated data file "link" into this.
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(szWorkDir, False, False, "FoxPro 2.5")
Dim szFieldList As String
szFieldList = "field1, field2, field3"
szSqlString = "INSERT INTO test SELECT " & szFieldList & " FROM link"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
But the following based on #wqw's suggestion is much better, as no predefined file is required
Private Sub Test1()
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(MyDataBasPath, False, False, "FoxPro 2.5")
Dim szFieldList As String
szSqlString = "ALTER TABLE work.dbf ADD COLUMN fred VARCHAR(30)"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
End Sub

Resources