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

Inserting date into a date unbound table with date datatype

17 16bit
I am trying to log my users action into a back-end table if a employee master data is change. Below is my code but i am getting an error with inserting a date.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "INSERT INTO TblMasterBackEnd " & _
  4.     "( HRAPSNO, AlphaCode, FirstName, LastName, " & _
  5.     "Branch, Dept, Loc, CostCtr, Netuser, " & _
  6.     "DateModified, DateStarted, PayRate, " & _
  7.     "AnnualSalary, BirthDate, Sex, MaritalStatus, " & _
  8.     "Dep, Position, DateCreated) " & _
  9.     "VALUES ('" & Me.txtHRAPSNo & "', '" & _
  10.     Me.txtAlphaCode & "','" & Me.txtFirstName & "','" & _
  11.     Me.txtLastName & "','" & Me.txtBranch & "','" & _
  12.     Me.txtDept & "', '" & Me.txtLoc & "', '" & _
  13.     Me.txtCostCtr & "', '" & Me.txtNetUser & "', #" & _
  14.     Me.txtDateModified & "#, #" & Me.txtDateStarted & "#, " & _
  15.     Me.txtPayRate & ", " & Me.txtAnnualSalary & ", #" & _
  16.     Me.txtBirthDate & "# ,'" & Me.cboSex & "', '" & _
  17.     Me.cboMaritalStatus & "'," & Me.txtDep & ",'" & _
  18.     Me.txtPosition & "', #" & Me.txtDatecreated & "# );"
  19.  
  20. DoCmd.RunSQL (strSQL)
  21. DoCmd.Save
  22. Me.Requery
Apr 26 '18 #1
3 1625
twinnyfo
3,653 Expert Mod 2GB
Adict,

First, please use the code tags when posting code, which is a rquirement of this forum. I have edited your post to reflect this. Also, concerning this, it is also wise to add line continuation marks on the forum so that users can view your code more easily, without scrolling all the way to the right.

Second, is this a direct cut and paste from your VBA editor? I have made some minor adjustments to the spacing of your code, but since I am not sure this was a direct cut and paste, I cannot say that this would solve anything. On the surface, I don't see anything that pos out concerning your dates.

Third, when you have trouble with SQL statements, it is often useful to have teh code print it to your Immediate Window so you can see exactly what your SQL statement contains before you execute it. Just add the statement Debug.Print strSQL to the line just prior to running your SQL statement (in this case, line 19).

Fourth, if you are inserting all these fields into a table (and it appears these values are currently on a form, is there a particular reason this form is not bound to TblMasterBackEnd? There may be a good reason for this, but it would be good to know.

Fifth, an alternate method (and one that I prefer) is to use a Recordset where you are directly updating the table--this is all preference, but for me, it allows me to more directly see what I am updating.

Sixth, you say you are getting an error with inserting a date. How do you know? What error are you getting and how do you know it is related to the date? This information will help us understand the nature ofyour problem.

Seventh, on the surface, it appears that you are creating redundant data in your Database, which most of us try to avoid unless it is absolutelye necessary. Based on the data listed, I don't see any fields that would much change over time, other than pay rate. Why not just add the index for the employee into the table and only the data that needs to be saved? Again, there could be a good reason for you saving so much information redundantly, but it would be good to know the reasons.

Thanks!
Apr 26 '18 #2
NeoPa
32,556 Expert Mod 16PB
Dates won't work when added that way into a SQL string unless you happen to live and work in North America (at least have your PC settings set that way).

See Literal DateTimes and Their Delimiters (#) for more on that, and How to Debug SQL String for general help when trying to work directly in SQL from VBA.
Apr 26 '18 #3
Adict
17 16bit
Thanks twinnyfo and Neopa. I have used recordset and achieved the results. The reason why i want a redundant data is to ensure that every data changes users make on the main master file. This is to achieve audit trails for master data.

Thanks much
Apr 27 '18 #4

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

Similar topics

15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
3
by: gazelle04 | last post by:
I'm trying to enter the current date into the table through code but there's an error in inserting the date. Whats wrong with this code: strSQL = "INSERT INTO University (, , )" strSQL =...
2
by: Paul | last post by:
I'm sure this isn't a difficult question, but I've been struggling trying to insert the current date into a sql server field. I've tried numerous suggestions that I've seen in newsgroups and...
8
by: markjerz | last post by:
Hi, I basically have two tables with the same structure. One is an archive of the other (backup). I want to essentially insert the data in to the other. I use: INSERT INTO table ( column,...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
1
by: vp.softverm | last post by:
hi all . Am facing problem with the date picker. when i click on date picker in a popup window. the date table is opened in the middle of the pop up window. and it is unable to scroll with...
2
by: haridharmajan | last post by:
I Need to add multiple date into a field using calender each date is to be separated by comma ie when I click on the show month it must display calender and when I click on a date it must inser it to...
4
by: mmclancy | last post by:
I'm using Oracle's SQL Developer to do the following: CREATE TABLE Account ( AccountID INT NOT NULL, CreditID INT NOT NULL, CardType VARCHAR(15) NOT NULL, ExpiryDate DATE, PRIMARY KEY...
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
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: 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.