Solved

Field type vbscript.

Posted on 2014-12-29
6
132 Views
Last Modified: 2015-01-19
Hello,

I run VBScript from Outlook to populate a text field.  I'm grabbing a value from a SQL table:

ctls("lblPartDesc").Caption = "Part Desc: " & rst.Fields("description")

When the field in SQL is a text field, it gives a data type mismatch error.  But when it is a varchar type it's fine.  I've tried cstr() and it still doesn't work.  Also, I'm not allow to change the field in the sql table to varchar because it's not my database.

Thanks, Joel
0
Comment
Question by:Genius123
  • 3
  • 2
6 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40522886
in the table what is the data type? given that what do you need?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40522996
When the field in SQL is a text field, it gives a data type mismatch error.
Can you confirm that the "description" column is in fact using the deprecated text data type?

If so, we may need to change your code where you SELECT it.  I suspect you are using SELECT *, right?

In any case:
1,  Post your code including the SELECT statement.
2. Tell us what data provider you are using.  If you don't know what that means just post the connection string (obviously obfuscating any sensitive info)
3. Post the schema to your table (CREATE TABLE statement).
0
 

Author Comment

by:Genius123
ID: 40523718
Certainly.  Please see the attached code.  The SQL field called "description" is a text data type.

select Case Name
case "PartName"

Dim DesciptionSQL

  Set ins = Item.GetInspector
  Set pgs = ins.ModifiedFormPages
  Set pg = pgs("Inventory")
  Set ctls = pg.Controls

'--------------

Set oADOConn = Nothing
Set oADOConn = CreateObject("ADODB.Connection")
If TypeName(oADOConn) = "Nothing" Then
	'MsgBox "Error"
	'Exit Function
End if

sConnectionString = "Driver={SQL Server}" & _
";Server=SQL02" & _
";Database=TGPInventory" & _
";User ID=inventoryadmin;Password=Wirelite!NT" & _
";"

err.Clear
'oADOConn.Mode = adModeWrite
oADOConn.ConnectionString = sConnectionString
oADOConn.Open
If err.Number <> 0 Then
	'MsgBox "(Error: " & err.Number & "/" & err.Description & ")"
	'Exit Function
End If

PartNameParse = split(Item.UserProperties("PartName"), " - ")

    sSQL = "SELECT * FROM framing_components WHERE compID = '" & PartNameParse(0) & "'"

Set rst = Nothing
Set rst = CreateObject("ADODB.Recordset")

rst.Open sSQL, oADOConn, adOpenForwardOnly	'for very fast reads

msgbox "asdf" & rst.Fields("description") & "asdf"

ctls("lblPartDesc").Caption = cstr(rst.Fields("description"))
'ctls("lblPartDesc").Caption = "Part Desc: " & rst.Fields("description")
ctls("lblQTY").Caption = "Part Desc: " & FormatCurrency(rst.Fields("l_cost"))

rst.Close
Set rst = Nothing
Set sSQL = Nothing
oADOConn.Close
Set oADOConn = Nothing
end select

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40524981
Exactly, as I guessed, you are using SELECT *.  This is never a good idea and as you have discovered is fatal with BLOBs.

Solution:  Change SELECT * to SELECT Col1, Col2, Col3 and place all your BLOBs at the end.  So in your case instead of this:
sSQL = "SELECT * FROM framing_components WHERE compID = '" & PartNameParse(0) & "'"

Do this:
sSQL = "SELECT l_cost, description FROM framing_components WHERE compID = '" & PartNameParse(0) & "'"
0
 

Accepted Solution

by:
Genius123 earned 0 total points
ID: 40549581
This did not work, however, when I convert the field to a varchar it works.  Here's the code:

sSQL = "SELECT compID,part_number, CONVERT(varchar(255), description) as descrip FROM framing_components WHERE part_number LIKE '%"& Trim(Item.UserProperties("PartNameSearch").value) & "%' or description LIKE '%"& Trim(Item.UserProperties("PartNameSearch").value) & "%' ORDER BY part_number"
0
 

Author Closing Comment

by:Genius123
ID: 40557333
Solved myself.  Thanks to others for help.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
address book on outlook 2016 mac 7 47
Date conversion in sql server 2012 6 26
outlook 4 22
Searching Outlook Email Archives 5 7
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now