|
-
Jun 9th, 2006, 04:03 AM
#1
Thread Starter
Addicted Member
OLE Object - INSERT Statement Problems
Hi guys,
Have tried looking for a solution to this problem on the net, but I've not been able to get very far. I've created a table with an OLE data type and I've also created a from that will allow users to enter information into this table. The issue is that I the INSERT statement I'm using in the VBA code is throwing this error -
"An expression you entered is the wrong data type for one of the arguments."
VB Code:
sql = "INSERT INTO .... blah blah blah .... Me.TxtAttachment.Value & ");"
The sql statement itself is ok - I've specified the correct field names and table name. The problem appears to be with the Value attribute of the TxtAttachment textbox.
Any idea where I'm going wrong on this?
Thanks in advance.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jun 9th, 2006, 12:48 PM
#2
Frenzied Member
Re: OLE Object - INSERT Statement Problems
If TxtAttachment is a textbox, you're probably getting a type mismatch because the value in the textbox is a string datatype, not ole.
Tengo mas preguntas que contestas
-
Jun 12th, 2006, 03:38 AM
#3
Thread Starter
Addicted Member
Re: OLE Object - INSERT Statement Problems
It is a textbox, yes. Is there another way to send an OLE object to a table via a form? My version of Access is 97.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jun 12th, 2006, 12:03 PM
#4
Frenzied Member
Re: OLE Object - INSERT Statement Problems
Sorry, never saved OLE. I tried Google Groups, but didn't find anything directly applicable. You may be able to use a string but it may need various headers, etc, to store it as an OLE object. Not sure why you'd want to do so, but whatever. Look up AppendChunk & related items in Help. But your error almost certainly comes from non matching data types. Post some code & the error message, maybe some one more familiar with OLE objects can help.
Tengo mas preguntas que contestas
-
Jun 13th, 2006, 04:58 AM
#5
Thread Starter
Addicted Member
Re: OLE Object - INSERT Statement Problems
Thanks, I'll check that out :-)
In the meantime, this is a more detailed view of the problem. The final field in my table is called Attachment and I've set its data type to OLE object. On my form, I have a text box called TxtAttachment. I have its properties set as follows -
VB Code:
Size Mode: Clip
Auto Activate: Double-Click
Display Type: Icon
Update Options: Automatic
OLE Type Allowed: Either
Upon clicking a command button, the following code is called -
VB Code:
sql = "INSERT INTO " & MyTableName & " ([Attachment]) VALUES (" & Me.TxtAttachment.Value & ");"
MsgBox sql
DoCmd.SetWarnings (False)
DoCmd.RunSQL (sql) ' - Synxtax error in query expression here
DoCmd.SetWarnings (True)
In Form View, I right click on the TxtAttachment box and select 'Insert Object' from the drop down menu (it's the only option on this menu that's enabled). I then select a PDF document from a directory. This appears to work fine (that is, a PDF document icon appears in the textbox).
Clicking on the command button then yields the following error -

And that's where I'm stumped...
Last edited by MethadoneBoy; Jun 13th, 2006 at 06:29 AM.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jun 13th, 2006, 05:48 AM
#6
Re: OLE Object - INSERT Statement Problems
You need ' characters aroud text/char fields, eg:
VB Code:
sql = "INSERT INTO " & MyTableName & " ([Attachment]) VALUES ('" & Me.TxtAttachment.Value & "');"
-
Jun 13th, 2006, 06:30 AM
#7
Thread Starter
Addicted Member
Re: OLE Object - INSERT Statement Problems
Tried that too. Same deal, I'm afraid.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jun 13th, 2006, 06:47 AM
#8
Re: OLE Object - INSERT Statement Problems
Ok, well in that case you'll need to use something other than SQL to insert values for that field (or change it to a text field, if you only want text in it).
I don't know how you can do it in Access, or DAO (which I think is what Access uses behind the scenes), but in in the Database FAQ there is an ADO example.
-
Jun 13th, 2006, 07:00 AM
#9
Re: OLE Object - INSERT Statement Problems
Can you post the runtime sql statement?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 08:23 AM
#10
Thread Starter
Addicted Member
Re: OLE Object - INSERT Statement Problems
 Originally Posted by si_the_geek
Ok, well in that case you'll need to use something other than SQL to insert values for that field (or change it to a text field, if you only want text in it).
I don't know how you can do it in Access, or DAO (which I think is what Access uses behind the scenes), but in in the Database FAQ there is an ADO example.
For the moment, I'm going to work around it by including a command button that will open a table-view subform that will allow a user to insert an OLE object into the table directly. Inelegant, but for the moment, it'll do. I'll take a look at that FAQ, thanks.
Can you post the runtime sql statement?
Er... you're really going to expose my pathetic knowledge of VBA here
I'm assuming you don't mean
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jun 13th, 2006, 08:27 AM
#11
Re: OLE Object - INSERT Statement Problems
Yes, your "INSERT INTO ... " part by placing a breakpoint on the sql = part so you can get it as its passed to the db with all parameters filled in etc.
I see your error statement shows 2 unsupported chars and was wondering what the statement actually looks like. Maybe there is an error in it.[/color]
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|