473,662 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.txtDa to.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandle r & "', -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 1119
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.n o> schreef in bericht
news:OT******** ********@TK2MSF TNGP03.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.txtDa to.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandle r & "', -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.txtDa to.Value, "Short date")

In the sql-statement I use
INSERT INTO tblToDo ( Dato, Bruker, Utfort, Melding, MeldingFra ) " & _
"SELECT " & dteDato & ", '" & strSaksbehandle r & "', -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
1449
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. I did not design the database.<g>
4
14888
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 strongly name which contains the class where the static variable is defined. This library can be referenced by multiple projects. I am fairly sure the static variable does not survive across the application boundry but does it within the application...
41
10658
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 = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
2
1930
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 = System.Web.HttpContext.Current.Session.Item("mySessionVar") But I can't figure out if it is possible to access a page level variable from within a class.
7
1484
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 format; mm/dd/yyyy. So thats fine, but when i look at the actual data in access instead of being a date such as 11/1/2006 its something like 12:19:43 AM. I have been beating my head against the wall trying to figure out what is going on. Does anyone...
1
25665
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 bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
0
35215
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 the sake of brevity I am sticking to common usage. Wherever the term procedure is used in this tutorial it actually refers to a subroutine or function. Definition of Scope The scope of a variable where this variable can be seen or accessed...
9
2054
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
20
12733
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 AutoExec macro calls a function "InitApplication" which, in turn, calls a function to set the value of a global string variable
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7365
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.