Hello everyone,
I am trying to make an insert query that inserts information using form values and a query that gets the id from the name of a field in the form.
I got a form that shows object name, date completed and department completed.
I am trying to do the following: - INSERT INTO DB (Person_id, Object_id, Date_completed, Department_completed) Values (Forms!Form1!Person_id, Querydata, Forms!Form2!Date_completed, Forms!Form2!Department_completed);
The query that i need data from selects the ID that belongs to the object_name in the form because this is a key field in the db i want to insert.
I tried many things but none seem to work. Do you guys have an idea how i can accomplish this?
Or is there a way to use the same syntax as forms!Formname!Formfield for queries?
Thanks in advance!
Here is the Logic as to how this can be accomplished, make your own substitutions where necessary. Certain assumptions were made concerning Data Types, Field Names, etc.: - Dim strSQL As String
-
Dim lngPersonID As Long
-
Dim dteDateCompleted As Date
-
Dim strDeptCompleted As String
-
Dim lngID As Long
-
-
'Variable Assignments taken from Form (No Validation, No Data Type Checking!)
-
lngPersonID = Me![Person_id]
-
dteDateCompleted = Me![Date_completed]
-
strDeptCompleted = Me![Department_completed]
-
-
lngID = DLookup("[ID]", "QueryData", "[Object Name]='" & Me![Object_Name] & "'")
-
-
strSQL = "INSERT INTO DB (Person_id, Object_id, Date_completed, Department_completed) Values (" & _
-
lngPersonID & "," & lngID & ",#" & dteDateCompleted & "#,'" & strDeptCompleted & "');"
-
-
CurrentDb.Execute strSQL, dbFailOnError
1 2044
Here is the Logic as to how this can be accomplished, make your own substitutions where necessary. Certain assumptions were made concerning Data Types, Field Names, etc.: - Dim strSQL As String
-
Dim lngPersonID As Long
-
Dim dteDateCompleted As Date
-
Dim strDeptCompleted As String
-
Dim lngID As Long
-
-
'Variable Assignments taken from Form (No Validation, No Data Type Checking!)
-
lngPersonID = Me![Person_id]
-
dteDateCompleted = Me![Date_completed]
-
strDeptCompleted = Me![Department_completed]
-
-
lngID = DLookup("[ID]", "QueryData", "[Object Name]='" & Me![Object_Name] & "'")
-
-
strSQL = "INSERT INTO DB (Person_id, Object_id, Date_completed, Department_completed) Values (" & _
-
lngPersonID & "," & lngID & ",#" & dteDateCompleted & "#,'" & strDeptCompleted & "');"
-
-
CurrentDb.Execute strSQL, dbFailOnError
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
Hi,
Have a database that contains various tables.
I need to run a query on two tables.
Table A contains a column called Titles
Table B contains a column called Uni_Titles
|
by: Paul |
last post by:
I have the query "SELECT * FROM RIGHT JOIN VisiterInfo ON .=VisiterInfo." which I use to select data from
two tables to display on screen. I use an Access file with an OleDb
connection.
I need...
|
by: talktozee |
last post by:
Hey, everyone!
Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A.
For...
|
by: Roland Hall |
last post by:
In Access you use "*" + + "*", + can be replaced with &
Calling a parameterized query in Access requires % be used in place of *,
however, all that I have read show dynamic SQL passed to Access:
...
|
by: tushar jadhav |
last post by:
Suppose,
i hv an 10 columns and next to that other columns in a DB Table. That 10 columns hv same default values & others are retriving from other table and are nearly 1000 records. How can i insert...
|
by: fitzini |
last post by:
Hi all,
I need to update multiple rows using a sub query. I've pasted sample code below to hopefully help recreate what I'm trying to do.
drop table dummy_test
create table dummy_test
(cmr...
|
by: dongletran06 |
last post by:
Hi,
Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input...
|
by: TechnoAtif |
last post by:
Hi ALL
I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
|
by: paulmitchell507 |
last post by:
I think I am attempting a simple procedure but I just can't figure out
the correct syntax. My asp (classic) page runs a SELECT query to
obtain dates and ID's from 2 tables
uSQL = "SELECT...
|
by: puneetmca |
last post by:
hi
i want to insert employees DOB into database through html forms but my code is not working....only empty record is shown in the database in edob ..rest of the records are working...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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,...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |