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

Saving a Date/Time Stamp from VB 2005 to MS Access

Hey folks,
Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form allows the employee to enter their UserID and select "Login" or "Logout" and then click a submit. When the submit button is clicked, I want the application to dum the NT Userename, UserID, status (Login or Logout) and a date/time stamp into an MS Access database. The Access database (MyDatabase.mdb) only has a single table ([Raw Data]), and the field in the table that is supposed to take the date/time stamp ([Date Stamp]) is a "Date/Time" field that is formatted to "General Date". The problem that I'm having is (I think) in the format of the date/time stamp that is being transfered to the Access database.

I know that I could convert it to a string format, change the format of the feild in the table to Text and save it that way, but I need to be able to report off of it so I need it to be an actual date/time stamp in the database.

The error message that I'm getting is :::
Syntax error (missing operator) in query expression '7/6/2007 4:43:21 PM'.



The code that I'm using to get to this point is:::::

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  2.  
  3.         'This is the code to submit a record to the database
  4.         'Process Flow
  5.  
  6.  
  7.         'Declaration of variables
  8.         Dim strNTUser As String
  9.         Dim MyDate As datetime
  10.         'Dim MyTime As String
  11.         Dim strUserID As String
  12.         Dim strStatus As String
  13.         Dim strMySQL As String
  14.         Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\My Database.mdb"""
  15.         Dim DB As System.Data.OleDb.OleDbConnection
  16.         DB = New OleDb.OleDbConnection(ConnectionString)
  17.  
  18.  
  19.  
  20.  
  21.         'Data Validation
  22.         If Me.txtUserID.Text = "" Or Not (IsNumeric(Me.txtUserID.Text)) Then
  23.             MsgBox("Please enter a valid User ID - Data Not Saved")
  24.             GoTo ExitMe
  25.         End If
  26.         If Me.cmbStatus.Text <> "Login" And Me.cmbStatus.Text <> "Logout" Then
  27.             MsgBox("Please select a valid Login/Logout status from the drop-down - Data Not Saved")
  28.             GoTo ExitMe
  29.         End If
  30.  
  31.  
  32.         'Assign values to variables
  33.         strNTUser = Environment.UserName
  34.         MyDate = Now
  35.         strUserID = Me.txtUserID.Text
  36.         strStatus = Me.cmbStatus.Text
  37.  
  38.  
  39.         'Move the data to the database
  40.         strMySQL = "Insert INTO [Raw Data]([Login ID], [Entry Type], [Entry Recorder], [Date Stamp]) VALUES (" & strUserID & ", " & strStatus & "," & strNTUser & ", " & MyDate & ")"
  41.         Dim DBCommand As OleDb.OleDbCommand
  42.  
  43.         DB.Open()
  44.         DBCommand = New OleDb.OleDbCommand(strMySQL, DB)
  45.         DBCommand.ExecuteNonQuery()
  46.         'DB.Close()
  47.  
  48. ExitMe:
  49.     End Sub


Any help you could give me on this would be greatly appreciated. Thanks in advance.
Jul 6 '07 #1
4 6771
kenobewan
4,871 Expert 4TB
Welcome to TSDN. I suggest finding what the General Date format is and use now, date or whatever is compatabile. HTH.
Jul 7 '07 #2
That's where my problem is.

When I enter sample data into the Access file it shows up in the field in the format "1/2/2007 12:00:00 PM".

When I go into my VB 2005 project and use a msgbox to output Now I get the exact same format.... "1/2/2007 12:00:00 PM".
Jul 11 '07 #3
Anyone have any suggestions?
Jul 13 '07 #4
Plater
7,872 Expert 4TB
When entering dates into a Date field, try treating them like a string. As in, put " around the value you are inserting.
Jul 13 '07 #5

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

Similar topics

7
by: Don | last post by:
Hi all, With regards to the following, how do I append the datetimestamp to the filenames in the form? The files are processed using the PHP script that follows below. Thanks in advance,...
2
by: Bert | last post by:
I would like to store a Date/Time stamp in a SQL tabel Now only the Date is stred and not the time. How to I get the time also This is the code (There is more, but that works) atSQLexe ex=new...
6
by: Mike Charney | last post by:
Is there a way to check a files date and time stamp from VBA in access. I have a need check a date stamp on a file that I am importing. Thanks in advance, Mike m charney at dunlap hospital...
0
by: Chirag Shukla | last post by:
Colleagues, I wanted to share a function to find if a date is in Daylight Saving Time or not. I was able to make this function faster than reading MSDN to find functions that .NET provides. I...
5
by: Des | last post by:
I have to do an events calender for a church. The events display will be limited to that week. If someone went in today Wed 24th I want to display 21st to 27th. I dont want any code samples, just...
3
by: phried1 | last post by:
I have created a form and inserted the following tables: Date Entered Time Entered Date Modified Time Modified Essentially how and where can I have these dates and times recorded so when the...
1
by: Susan Bricker | last post by:
Greetings. I have a report (actually all of my reports in an MDB) that I want to date/time stamp at the bottom. Previously, I had used the builtin function of Now(). I thought that would give...
8
by: Trev | last post by:
Hi Can anyone point me in the right direction here, I would like to open a table in access 2003 by date. I have an asp web page which needs to read data from a table with each days today's date...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
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
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?
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.