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

Select a value of a date field and store as a variable

Can anyone help me with VBA code for selecting the value of a field in a record and storing it as a variable I can then INSERT INTO another table. I will also want to use this variable to rename a file. eg. sample.txt with become sample091506.txt. The info I need to grab is a date that is stored in a field called [LocateDate]. Thanks for any help!
Sep 22 '06 #1
6 2154
Should I use a SELECT DISTINCT statement? I keep getting Data Type Mismatch because the value I want is a DATE. My Statement reads
Dim TempDate as DATE

SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp
Sep 22 '06 #2
PEB
1,418 Expert 1GB
Should I use a SELECT DISTINCT statement? I keep getting Data Type Mismatch because the value I want is a DATE. My Statement reads
Dim TempDate as DATE

SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp
1. So to have a Global Variable use:

Global TempDate

in a module! If you don't want to be global you can use in your Form

Dim TempDate

2. To set the variable after updating event your field LocateDate:

TempDate=MarketDataTemp.LocateDate

3. In your SQL: SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp you need to put ; at the end

4. to create your file name use

[my_file_name]=Mid([my_file_name],1,Len([my_file_name])-4)+TempDate+".txt"

:)
Sep 22 '06 #3
1. So to have a Global Variable use:

Global TempDate

in a module! If you don't want to be global you can use in your Form

Dim TempDate

2. To set the variable after updating event your field LocateDate:

TempDate=MarketDataTemp.LocateDate

3. In your SQL: SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp you need to put ; at the end

4. to create your file name use

[my_file_name]=Mid([my_file_name],1,Len([my_file_name])-4)+TempDate+".txt"

:)
Thank you for your help. So that I understand, to obtain the date value from tbl#1 and then add a new record to tbl#2 with this value, I would use the code:

Dim TempDate
SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp
docmd.runSQL "INSERT INTO tbl#2 DateField,NoOfZeros VALUES TempDate, 60"
Sep 22 '06 #4
PEB
1,418 Expert 1GB
Oppa,
In fact no! Sorry with those codes i've not understand what did you mean!

Expand|Select|Wrap|Line Numbers
  1. Dim TempDate
  2. tempdate=dfirst("LocateDate", "MarketDataTemp","")
  3. docmd.runSQL "INSERT INTO tbl#2 (DateField,NoOfZeros) VALUES (CVDATE('"& str(TempDate) & "'), 60)"
  4.  

:)

If pb here we are...

Thank you for your help. So that I understand, to obtain the date value from tbl#1 and then add a new record to tbl#2 with this value, I would use the code:

Dim TempDate
SELECT DISTINCT MarketDataTemp.LocateDate AS TempDate FROM MarketDataTemp
docmd.runSQL "INSERT INTO tbl#2 DateField,NoOfZeros VALUES TempDate, 60"
Sep 23 '06 #5
Oppa,
In fact no! Sorry with those codes i've not understand what did you mean!

Expand|Select|Wrap|Line Numbers
  1. Dim TempDate
  2. tempdate=dfirst("LocateDate", "MarketDataTemp","")
  3. docmd.runSQL "INSERT INTO tbl#2 (DateField,NoOfZeros) VALUES (CVDATE('"& str(TempDate) & "'), 60)"
  4.  

:)

If pb here we are...
Thank you so much for your help!! It worked great!
Sep 25 '06 #6
PEB
1,418 Expert 1GB
:)

Have a nice eveneing!

:)
Sep 25 '06 #7

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

Similar topics

5
by: Mark | last post by:
Hi - I have set-up security for my users - the security is held in a text field, separated by a comma. If the users a member of groups 1, 5 and 6 - the usergroups field is set to 1,5,6 - to...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
by: tedhekman | last post by:
Hi there! I am pretty new to Access, have been loving learning it! I have a problem here I can't even begin to figure out. Here is what I need: Given 1 Date and 1 Store, retrieve the following...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
2
by: Brad | last post by:
get the following error when I try to save a date: When converting a string to DateTime, parse the string to take the date before putting each variable in the DateTime object. I was using a...
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 ...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: sbettadpur | last post by:
Hello everybody I have some issues in my program. Let me explain my requirement briefly, i am using php, mysql, javascript and ajax for my application. when my application opens means if...
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: 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: 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
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
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 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.