Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 25th, 2004, 09:54 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT INTO QUERY

Hi there,

I am using INSERT INTO query in order to add records to the access db using VBA. My code is as follows:

rivate Sub cmd_OK_Click()
    Dim wrkJet As DAO.Workspace
    Dim db As DAO.Database
    Dim dbname As String
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim Q As DAO.QueryDef

    dbname = "C:\Documents and Settings\sanju\Desktop\Project\Commcare.mdb"
    Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
    Set db = wrkJet.OpenDatabase(dbname, , True, "Microsoft.Jet.OLEDB.3.51")
    strSQL = "INSERT INTO MasterAccountDetails VALUES (txt_AccName.text, txt_Desc.text, CB_Period.Value, txt_Template.text, txt_Midstarttime.text, txt_Midendtime.text );"
    Set Q = db.CreateQueryDef("")
    Q.Sql = strSQL
    Q.Execute
    Q.Close
    db.Close
    wrkJet.Close

But unfortunately my code generates a run time error stating "Too few parameters.Expected 6."
Does anyone know how to solve this prob?
Thanks a lot for u r help in advance.
Sanjna...

Reply With Quote
  #2 (permalink)  
Old November 25th, 2004, 10:33 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

It seems you are inserting less values in the table.

If you want to insert less columns in the table then use the following syntax..

insert into tablename (column_1,column_2) values ('value_1','value_2')

Om Prakash
Reply With Quote
  #3 (permalink)  
Old November 25th, 2004, 11:18 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's the problem. I am inserting values for all the fields in the table. But i am getting the same error msg.


Reply With Quote
  #4 (permalink)  
Old November 25th, 2004, 11:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you have an autonumber field in your table? If so, use the procedure from Om Prakash
Reply With Quote
  #5 (permalink)  
Old November 25th, 2004, 12:00 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't have auto number field in my table.

Reply With Quote
  #6 (permalink)  
Old November 26th, 2004, 12:41 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the data is coming in the fields:

txt_AccName.text,
txt_Desc.text,
CB_Period.Value,
txt_Template.text,
txt_Midstarttime.text,
txt_Midendtime.text

Other reason could be:
One of the column names specified in a select statement does not exist in the table being queried.


Om Prakash
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Into Query. rupen Access VBA 5 July 30th, 2007 09:58 AM
Where does insert query go? bph Access VBA 5 June 12th, 2007 12:26 PM
New Insert Query Neal SQL Server 2000 3 May 8th, 2007 01:22 PM
INSERT Query Neal SQL Server 2000 2 May 3rd, 2007 05:18 PM
I solved insert query.now see this Update Query. amit_mande@yahoo.com VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM



All times are GMT -4. The time now is 06:07 AM.


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