MS Access VBA to update table field with rich-text textbox value - sql

I have a form with an unbound Rich Text textbox control (named: tbxNote). I am using the following code to update the target table (named: tblSupeGenNotes) with the values from various controls on the form:
dbs.Execute "UPDATE tblSupeGenNotes " & _
"SET [NoteDate] = #" & Me.tbxNoteDate & "#, " & _
"[SupeType] = " & Me.cbxSupeType & ", " & _
"[SupeAlerts] = " & alrt & ", " & _
"[Note] = " & Chr(34) & Me.tbxNote & Chr(34) & " " & _
"WHERE [SupeGenNoteID] = " & Me.tbxSupeGenNoteID & ";"
All data is getting into the target table in the correct fields with the correct values except that the [Note] field that pulls its data from the Rich Text textbox control (me.tbxNote) is including HTML tags in the table field result. For example, I get the following: "<<div>>Sample! {&}nbsp;I do not understand what is happening!<<\_div_>>". (Sorry, I had to "fake" the HTML tags because the forum changes it to HTML!)
How do I get rid of the HTML tags but maintain the HTML/rich text formatting?

AH! I figured it out. Hope this is useful to others:
I had only set the textbox control on the form to Rich Text. I needed to also go into the target data table itself (tblSupeGenNotes) and set the [Note] field to have a "Text Format" property of "Rich Text" instead of "Plain Text".
After making that change, the rich text displays properly on the form, and, the text with formatting is correctly transferred into the target table.

Related

display table data in a list box (access form)

I want display table data in a list box with this code:
Me.List_history.RowSource = "SELECT Date " & _
"FROM Leaves " & _
"WHERE CodePersonali = " & Nz(Me.CodePersonali.Value)
but the list box doesn't display anything
List_history = my list box name
Date = field name in leave table
Date is a reserved word (it's a function), so you shouldn't use it as column name. If you must, put it between square brackets [Date].
If CodePersonali is a text column, you need to put the value between ''.
That would be
Me.List_history.RowSource = "SELECT [Date] " & _
"FROM Leaves " & _
"WHERE CodePersonali = '" & Nz(Me.CodePersonali.Value) & "'"

Trouble with shape append on VB6

I'm working on VB6 and I try to create an report, for create this report I'm using shape with 3 levels.
"SHAPE APPEND " & _
" New adVarChar(15) As zoneId," & _
" New adVarChar(15) As zoneNam," & _
" ((SHAPE APPEND " & _
" New adVarChar(30) As ID, New adVarChar(30) As costumerName," & _
" ((SHAPE APPEND " & _
" New adVarChar(15) As productCode, New adVarChar(25) As produtName, New product(30) As product," & _
" New adVarChar(30) As price," & _
" New addouble As disount)" & _
" RELATE productCode to productCode) AS COST)" & _
" RELATE zoneId to zoneId) As FECHAS", _
"Provider=MSDataShape;Data Provider=None"
This code run and don't show error but in execution time don't show data and the query test work perfect. I'm making the report using the vb designer and the data's bind using DataField and DataMember names on an array.
Example:
rsCostumersZone.addNew Array("ZONEID", "ZONENAME"), (rsDataZone!tbz_id, rsDataZone!tbz_name)
I appreciate any hint on the error.
Put a messagebox between your load or set data source statement and 'Report.show' statement. I vaguely remember this issue. If it works you can then change the messagebox to something like DoEvents or Wait.

VBA Assign a RecordSet Field to a ComboBox

I have the following code:
sSQL = "SELECT CODER FROM " & dbfname & " IN " & dir & " WHERE TRIM(CODEK) = TRIM(kCode)"
Combo29.RowSource = sSQL
Combo29.Requery
, where "CODER" is a field in the dbf file. "CODEK" is also a field in that dbf file, which im comparing with the string kCode.
When I run the code and when I click on the combobox, it asks me to enter arguments instead of showing the selected arguments. The RowSource type is set to Table/Query.
Is the assigning statement incorrect and how can I modify it to show me list of results from the SQL statement?
If I understand your problem correctly kCode is a string in VBA so you'll have to set up your SQL string the following way
sSQL = "SELECT CODER FROM " & dbfname & " IN " & dir & " WHERE TRIM(CODEK) = TRIM('" & kCode & "')"`

datatype mismatch in criteria expression in MS Access

I am creating form in access in which i have to implement cascading combo boxes , data in lower combo box is dependent on its parent value selected by user. Here is form
on left side is structure of the table and on right side is form. Problem is I am getting error of data type mismatch , unable to understand why this is happening. In the afterupdate event of Diametre of Drill I am populating cutting speed . Whenever I press drop down of Cutting Speed "Datatype mismatch in criteria expression" occurs. Here is code of afterupdate event of Diametre of Drill
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '` `cboDiameterDrilling.Value ' " & _`
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub
I think problem is in WHERE Clause . Any help would be greatly appreciated. Thank you
You've surrounded the reference to the object's value (cboDiameterDrilling.Value ) in single quotes.
AND tblDrilling.diaOfDrill = ' & cboDiameterDrilling.Value & "'"
Solution : AND tblDrilling.diaOfDrill = " & cboDiameterDrilling.Value & " " & _
I think you missed a ". Try:
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '" & cboDiameterDrilling.Value & "' " & _
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub

DLookup ControlSource

Summary:
I want to display a value (in a text box) stored in another form upon choosing specific values from combo boxes.
I want to pass the two combo box values I have into the DLoopup property but every time I do so it gives me an error.
Below is the code is inserted in the control source property of a text box:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] ='" & [Combo5] & "'")
This gives me an "#Error" in the text box.
Also tried the following but gives me "#NAME" error:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] = '" & [Combo5.Value] & " And [Program_Name] = '" & [Combo7.Value] & "'")
You need to get your delimiters sorted out. AFAIR Budget Year is a number:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5])
When you are passing a value to a numeric type field, you do not use delimiters, for text, you use quotes, either 'Abc' or "Abc", for dates, use hash (#) #2012/11/31#.
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5] & " And [Program_Name] = '" & [Combo7.Value] & "'")