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

Query a table then return the value to another table

Hi there,

Let me explain my problem more clearly:

I have:
a form FRM_Main
2 tables TBL_2007_OT and TBL_2007_Date
a querry QRY_Dates_2007

The TBL_2007_Date is a number from 1 to 365 as primary key and the date associated to it. ex: 1 would be 1/1/2007.

The TBL_2007_OT would have a field named Date_ID where I want the number from TBL_2007_Date to be stored.

Now my form have a day combo box a month combo box and a year combo box which then populate a disabled textbox and it look like this (1/1/2007).

Everything works fine. As you can see, there is nowhere in the form where we talk about a number from 1 to 365.

What I want to do is, upon click of my save button, search the table TBL_2007_Date for the value of the textbox and then store the number from 1 to 365 in the table TBL_2007_OT field Date_ID

Tell me if you need more informations

Regards
Dec 19 '07 #1
2 1507
jaxjagfan
254 Expert 100+
It will be similar to this. You will need to use the DLookup to find the value and a Insert (Append) to add the value to the other table. Add this to your button.

Dim iDt
Dim strSQL As String
iDt = DLookup("[Date_ID]", "TBL_2007_Date", "[YourDateColumn] =" _
& Forms![FRM_Main]!YourTextBox)
strSQL = "Insert Into TBL_2007_OT (Date_ID) Values (" & iDt & ");"
DoCmd.RunSQL strSQL

If you need dates to have ID's why not use:

CLNG(Format(Date(),"mmddyyyy") - This would return 12192007 using today's date. It would be unique and easily distinguishable.

If you need the day number similar to your sample (1-365 for this year or 1-366 for next year) I would do a DateDiff + 1. DateDiff(SelectedDate,cdate("1/1/" & SelectedYear)) + 1 - this would return 352 (12/19/2007 - 1/1/2007) + 1.
Dec 19 '07 #2
Thanks a lot "jaxjagfan"

I will try this rigth now and let you know if it works.
Dec 19 '07 #3

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
3
by: Thomas R. Hummel | last post by:
Hi, I was just helping a coworker optimize a query. He had two versions: one which used UNION for each value for which he was tallying results and another query which used GROUP BY. Here is an...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
0
by: Jeff Boes | last post by:
I hope this helps someone else ... I had struggled some time ago with attempts to get a rank of values query to work, but then I gave up and set it aside. I had another reason to attack it, and in...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while...
6
by: lesperancer | last post by:
SELECT distinct b.t_orno, b.t_pono FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS tblFilterDate_1 WHERE (((b.t_yearMonth) Between . And .)); tblMonthlyBooking is a sql server...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
3
by: bob laughland | last post by:
Hi All, I have another SQL question, and this one is going to be difficult to explain. I have a table like this rowid name changed 1 a 1 1 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.