473,386 Members | 1,606 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.

Datefield from variable into a datefield in an access b

I use a DateTimePicker to get a date.
I want to add this date into an access table.
I use a variable like
Dim dteDato As Date = Format(Me.txtDato.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandler & "', -1, '" & strMelding &
"', 'Fra Peres'", con)
....

The date shows as #7/1/2006#, but when I run the sql I get a syntax-error
If I replace the dteDato in the sql with #7/1/2006# it works OK.

reidarT


Jun 29 '06 #1
2 1112
Reidar,

Especially datetimes should be handled with parameters.

See here this simple sample.

http://msdn.microsoft.com/vstudio/express/vwd/

Be aware that this is the most simple sample, there are more samples on our
website.

I hope this helps,

Cor

"reidarT" <re****@eivon.no> schreef in bericht
news:OT****************@TK2MSFTNGP03.phx.gbl...
I use a DateTimePicker to get a date.
I want to add this date into an access table.
I use a variable like
Dim dteDato As Date = Format(Me.txtDato.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandler & "', -1, '" & strMelding &
"', 'Fra Peres'", con)
...

The date shows as #7/1/2006#, but when I run the sql I get a syntax-error
If I replace the dteDato in the sql with #7/1/2006# it works OK.

reidarT

Jun 30 '06 #2
Hello, reidarT,

Try replacing dteDato in your SQL with Format(dteDato, "#yyyy-MM-dd#").

Note that I am recommending using a fixed date format. As I recall,
Access by default uses m/d/y, but it also happily accepts the (far
better) ISO format.

Groetjes,
Randy
reidarT wrote:
I use a DateTimePicker to get a date.
I want to add this date into an access table.
I use a variable like
Dim dteDato As Date = Format(Me.txtDato.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandler & "', -1, '" & strMelding &
"', 'Fra Peres'", con)
...

The date shows as #7/1/2006#, but when I run the sql I get a syntax-error
If I replace the dteDato in the sql with #7/1/2006# it works OK.

reidarT

Jun 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Frank Rocco | last post by:
Hello, We have a database that as two datetime fields. field1 has the date and field2 has the time. I need to merge field1 & field2 into field1. Can someone help me with this syntax? P.S....
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
2
by: Corey B | last post by:
Is there a way for an instance of a custom class to access an ASPX page level variable? I know that I can access a Session variable from within a class using the following code: myClassVar =...
7
by: rbmako69 | last post by:
I'm using a flash form to input some data into my access database. one of the fields is a type=datefield. When i output the actual data just before the sql insert that date is in the correct...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
9
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
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: 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,...

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.