473,378 Members | 1,462 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,378 software developers and data experts.

Insert Into - Code

Hello,
I'm relatively new to VBA, and was wondering if someone would help me debug the code below. I want to put it in a form, so that when I click "OK" it inserts a new record into the ActionItems table. I only want to insert the one field "Review_ID" which is a foreign key, although the table has many other fields. The primary key in the table is ActionItem_ID, and is an Autonumber. The primary key is the only field indexed with "Yes (No Duplicates)". (Although I do have a few fields indexed with "Yes (Duplicates OK)". After the entry is added I want to open a second form "Add ActionItem Template" to edit the remaining fields in the table, and close my filtering form "Add ActionItem Form". (please ignore the blatant disregard for naming conventions, I am working in a database I did not design). Any help you could offer would be very much appreciated.

Code Start:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OK_Click()
  2.   Me.Visible = False
  3.  
  4.     INSERT INTO ActionItems(Review_ID)
  5.     VALUES ('" + Review_Date.Value + "')"
  6.     SELECT * FROM ActionItems"
  7.     DoCmd.OpenForm "Add ActionItem Template"
  8.     DoCmd.Close acForm, "Add Action Item Form"
  9. End Sub
  10.  
Code End

Sincerely,
danyork
Oct 4 '07 #1
2 1604
TSIGOS1
24
try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OK_Click()
  2. Me.Visible = False
  3.  
  4. constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
  5.         "mydb.mdb" & ";"
  6.  
  7. Dim con As ADODB.Connection
  8. Dim db As Database
  9. Set con = New ADODB.Connection
  10. con.ConnectionString = constr
  11. con.Open
  12.  
  13.       INSstr = "INSERT INTO" & "ActionItems Review_ID" &
  14. "VALUES"  & Review_Date.Value &";"
  15.   Debug.Print INSstr
  16. con.Execute INSstr
  17.  
  18. DoCmd.OpenForm "Add ActionItem Template"
  19. DoCmd.Close acForm, "Add Action Item Form"
  20.  
  21.            End If
  22.  
  23. End Sub
Oct 4 '07 #2
Thanks alot, I appreciate your help
Oct 4 '07 #3

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

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.