troubleshooting Question

Access VBA Best date format for SQL insert statement

Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on
SQLMicrosoft AccessVBA
3 Comments1 Solution17 ViewsLast Modified:
Hi
In Access when inserting a date from a text box that has a date format of dd-mm-yyyy
I use the code in the second part below to convert the dates. Is this the best method or is there a better way such as the following.
Format(Me.DateReceived, "yyyy-mm-dd")

Open in new window


    Dim oDateReceived As String: oDateReceived = Format(Me.DateReceived, "Medium Date")
    
    Dim oLastRegRenewal As String: oLastRegRenewal = Format(Me.DateReceived, "Medium Date")
    Dim oRegExpiryDate As String: oRegExpiryDate = Format(Me.ExpiryDate, "Medium Date")
    
    
    'Create Firearm
    ''Dim SN2 As String: SN2 = Nz(txtSN2, "")
    sSQL = "Insert into t_Arms (LicenceNumberFK,Manufacturer,Country,[Year Manuf],Model,Calibre1,Calibre2,SerialNo,SerialNo2,SerialNo3,ArmType,ActionType,"
    sSQL = sSQL & "Status,Source,SourceComment,Remarks,CreatedDTG,LastRegRenewal,RegExpiryDate,ProcessingOfficer,Image,AssaultRifle,Latitude,Longitude,Location)"
    sSQL = sSQL & " values ("
    sSQL = sSQL & Me.LicenceNumber & ","
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Manufacturer, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.CountryOfManufacture, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.YearOfManufacture, "Unknown")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Model, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Calibre1, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Calibre2, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.SerialNo, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.SerialNo2, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.SerialNo3, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.ArmType, "")) & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.ActionType, "")) & "',"
    sSQL = sSQL & "'Registered'," '[Status]
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Source_Combo, "")) & "'," '[Source]
    sSQL = sSQL & "'" & SQLSafe(Me.SourceComment) & "'," '[Source Comment]
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Remarks, "")) & "'," '[Remarks]
    sSQL = sSQL & "'" & Now() & "',"
    sSQL = sSQL & "'" & oLastRegRenewal & "',"
    sSQL = sSQL & "'" & oRegExpiryDate & "',"
    sSQL = sSQL & "'" & SQLSafe(sUserCode) & "',"
    sSQL = sSQL & "'" & SQLSafe(oGatherPictures) & "',"
    sSQL = sSQL & "'" & oAssaultRifle & "',"
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Latitude, "0")) & "'," 'Zero length not allowed
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Longitude, "0")) & "'," 'Zero length not allowed
    sSQL = sSQL & "'" & SQLSafe(Nz(Me.Location, "None Specified")) & "')"

Open in new window



Open in new window



ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 3 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 3 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004