Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2011, 12:52 AM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Just Trying Simple in Access 2007 (Windows 7)

Hello, I am just trying to do a simple Access database to see a productivity boost at work hopefully. I cannot get this code here to work as I get an error message that says:

Run-Time error '3134'
Sytax Error in INSERT INTO statement

using this code...


Private Sub btnAdd_Click()
Dim stra As String
Dim strSQL1 As String

stra = [txtTest].Value
strSQL1 = " (INSERT INTO tblTest VALUES (' " & stra & " ') "

DoCmd.RunSQL strSQL1

End Sub

I'm just trying to save a string into a table.
The exact same code worked prior to windows 7 conversion. I cannot get an INSERT statement to work so I set up a test table with a single text insert. I get integers and booleans to work.

And I'm sorry if this is a super basic question.

Last edited by wonesor; January 15th, 2011 at 01:20 AM..
 
Old January 15th, 2011, 11:53 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

There is an extra ( before the INSERT. Try removing it.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
The Following User Says Thank You to HiTechCoach For This Useful Post:
wonesor (January 15th, 2011)
 
Old January 15th, 2011, 01:55 PM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Post

Thanks for the reply HiTechCoach!

I tried it, changed my statement to:

Option Compare Database

Private Sub btnAdd_Click()
Dim stra As String
Dim strSQL1 As String

stra = [txtTest].Value
strSQL1 = "(INSERT INTO tblTest VALUES (' " & stra & " ')"

DoCmd.RunSQL strSQL1

End Sub

and still get the same error message. The simple problem is I just can't seem to add a string to my table. I'm at a loss here as this is such a basic thing. I am able to add strings when I don't use the VBA. Does this have something to do with references perhaps? I have scoured all resources on them and was believing I have all that I needed.
 
Old January 15th, 2011, 07:32 PM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Red face It Works Now

As it turns out I had a spelling error. The son-in-law came over and scoped it out. None other than Mr. HotWu himself. It now works and sorry for the trouble.
 
Old January 15th, 2011, 07:45 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

Thank you for the update.

Glad to hear you got it figured out.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to specify relative path to Access 2007 in ADO connection string? [Excel 2007] sektor Excel VBA 4 September 3rd, 2009 11:59 PM
Disabling Simple File Sharing in Windows XP. firblazer BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 April 14th, 2008 12:10 PM
Access 2007 JohnBoy VB.NET 2002/2003 Basics 1 March 16th, 2008 09:33 PM
trying to create simple windows app, help please Mibble C# 0 January 18th, 2007 12:07 PM
Access 2007 - wtf? mmcdonal Access 7 December 19th, 2006 08:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.