473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Insert query in VBA access

hi, I have a problem with a insert query in vba acces. each time run it, there is an error message "run-time error 424, Object require"
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2.     Dim dbs As Database
  3.     Set dbs = CurrentDb
  4.     'Insert all records of selected film id in tickets table
  5.      dbs.Execute ("INSERT INTO tickets_tbl ( pid, seats, total )SELECT projections_tbl.pid, temp1.seats, " & Str(Froms!tickets!total) & " FROM Projections_tbl, temp1 WHERE sel = true and Projections_tbl.rid = temp1.rid")
  6.     'Update number of seats left in projection table
  7.     dbs.Execute ("UPDATE projections_tbl INNER JOIN temp1 ON projections_tbl.rid = temp1.rid SET seats_left = seats_left-temp1.seats WHERE fid = " & Str(Forms!tickets!fid) & "")
  8.     'Delete all contents in temp1
  9.     dbs.Execute ("DELETE * FROM temp1")
  10.     'clear total,paind and change
  11.     Me.paid = ""
  12.     Me.change = ""
  13.     Me.fid = ""
  14.     Me.title = ""
  15.     Me.duration = ""
  16.     Me.rated = ""
  17.     Me.Refresh
  18. End Sub
the dbs.execute ("insert into...") is highlighted!!

can anyone help me?
thanks
tarounen.
Mar 27 '12 #1
2 2227
NeoPa
32,556 Expert Mod 16PB
I have two suggestions for you :
  1. As the items from the DAO library and the ADODB library overlap so much, it is very important to declare such objects explicitly :
    Expand|Select|Wrap|Line Numbers
    1. Dim dbs As DAO.Database
  2. Check out How to Debug SQL String. Your problem is with the SQL string so posting the VBA code is not too helpful. It would make sense to post the SQL string so that it's readable. Posting it all in a small number of very long lines will be appreciated by no-one, which might mean they look elsewhere for questions to help with ;-)
Mar 27 '12 #2
mshmyob
904 Expert 512MB
I don't know if this part is a typo

Expand|Select|Wrap|Line Numbers
  1. Str(Froms!tickets!total)
  2.  
but it should be Forms not Froms.

Also your last quote should be after the ) not before.

Expand|Select|Wrap|Line Numbers
  1. Projections_tbl.rid = temp1.rid") 
  2.  
cheers,
Mar 28 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
5
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: ...
1
by: Snuyt | last post by:
Hello, I have a insert query in an Access database: q="INSERT INTO tbl (f1, f2) VALUES ('1', '2')" the table has 3 fields: id: autonumber, f2: text, f3: text how do I retrieve the id from...
2
by: maravinds | last post by:
Hallo everyone, I have two tables in the database table1(col1,col3,col2) and table2(col1, col2). First of all i will have to select col2 from database and for each and every value of col2 i need o...
2
candicemc
by: candicemc | last post by:
Can anyone help me please?! I am a beginner and i am in desperate need of help. I have to create an insert query in access using a table i've already created called "madlibs" Then I have to create...
1
by: Luqman | last post by:
I have created a Insert Query in Sql Data Source using Oracle Database, with the parameters, and its connected with DetailView Control. When I try to Insert through DetailView Control, Illegal...
2
by: kaushalgajjar | last post by:
Hi there i have a problem in inserting a query to Access database. i am having a column which is AutoNumber and if i skip that field in insert query from vb.net then it is giving me an error "Syntax...
1
by: billypit | last post by:
Hi, In my project i have one table production.Now i have to make application in which i have to insert new data in table by fields of form made in access.I don't know how to use form field's values...
1
by: hnpatel | last post by:
Hi to all, How to use insert query in php? I m using ODBC connection with access database.I want to save data in table. I m using database 'PHPDB1'. Table Name 'EDETAIL'. There r...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.