Solved

Field type vbscript.

Posted on 2014-12-29
6
142 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Find out what you should include to make the best professional email signature for your organization.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

17 Experts available now in Live!

Get 1:1 Help Now