Results 1 to 6 of 6
  1. #1
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43

    Date entry into the table by using vba

    While entering the date into the table using the following code



    Private Sub cmdSave_Click()
    Dim sSQL As String
    Dim Basefk As Long

    Basefk = Nz(Me.cboAllotSlot, 0)
    If Basefk > 0 Then
    sSQL = "INSERT INTO tblbasecall(baseID_FK,callID_FK,calldate)"
    sSQL = sSQL & "VALUES (" & Me.cboAllcall.column(1) & "," & mid & " ," & me.txtcalldate & " );"
    Debug.Print sSQL
    CurrentDb.Execute sSQL, dbFailOnError
    End If
    End Sub

    i got the values like 1-5-1894,2-6-1894 all the values are from 1800s series. why the code not inserting the same value as entered into the text box of the form.

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    Date entry into the table by using vba

    If The txtcalldate is date time so should be surrounded by # tags in sql

    If it isn't you need to format it as a date in the sql statement

    Sent from my iPhone using Tapatalk

  3. #3
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    it works fine with #

    thanks a lot

  4. #4
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    Quote Originally Posted by andy49 View Post
    If The txtcalldate is date time so should be surrounded by # tags in sql

    If it isn't you need to format it as a date in the sql statement

    Sent from my iPhone using Tapatalk
    #tags are working fine but i want to draw your attention towards the date and month. In the form i have entered 7-1-2017 (dd-mm-yyyy) but it is entering 1-7-2017 (dd-mm-yyyy) from month of jan it enterd july. Where there is wrong in the coding. But for higher dates after 12th (day of the month) it works fine.

  5. #5
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    Why it is happening so i have searched on bing and google. it shows that SQL uses the format of type mm/dd/yyyy while inserting into table. hot to convert it to dd/mm/yyyy

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    sSQL = sSQL & "VALUES (" & Me.cboAllcall.column(1) & "," & mid & " ," & me.txtcalldate & " );"
    What is "mid"?? Be aware that "mid" is a reserved word (and a built-in function) and shouldn't be used as an object name.

    When working with dates, the dates MUST be in USA format (MM\DD\YYYY)
    See Allen Browne's site http://allenbrowne.com/ser-30.html
    Scroll down to Dates in Strings

    If you add the function SQLDate, the SQL would look something like
    Code:
    sSQL = sSQL & "VALUES (" & Me.cboAllcall.column(1) &  "," & mid & " ," & SQLDate(me.txtcalldate) & " );"
    Note: the function "SQLDate" adds the date delimiters, so you don't need to add them.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. last entry by date
    By yaronym in forum Queries
    Replies: 3
    Last Post: 01-23-2017, 11:46 AM
  2. Query date entry
    By NightWalker in forum Queries
    Replies: 3
    Last Post: 07-07-2016, 07:57 AM
  3. Replies: 1
    Last Post: 01-18-2014, 08:33 PM
  4. Automatic Date Entry
    By Al77 in forum Access
    Replies: 3
    Last Post: 02-27-2012, 12:06 PM
  5. Date entry
    By kellyd in forum Access
    Replies: 3
    Last Post: 09-24-2009, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums