can anyone help me where am I doing wrong.. im building an update statement with multiple columns to update MSQL with VBA and values from Excel. heres my simple code, Im parsing variable in function to execute SQL command (I have a table name "People" and I have define all the column) below:
Function GetUpdateTextSQL(PIC As String,
Customer As String,
DOB As Date,
Rank As String,
Organization As String,
Status As String,
Gender As String,
Religion As String,
Hobby As String,
CreatedBy1 As String,
CreatedOn1 As Date,
ChangedBy1 As String,
ChangedOn1 As Date,
PeopleID As Integer) As String
SQLStr = _
"UPDATE People" & _
"SET PIC = " & _
"'" & PIC & "', Customer = '" & Customer & "'," & _
"DOB = '" & Format(DOB, "yyyy-mm-dd") & "', Rank = '" & Rank & "'," & _
"Organization = '" & Organization & "',Status = '" & Status & "', Gender = '" & Gender & "'," & _
"Religion = '" & Religion & "', Hobby = '" & Hobby & "'," & _
"CreatedBy = '" & CreatedBy1 & "', CreatedOn = '" & CreatedOn1 & "'," & _
"ChangedBy = '" & ChangedBy1 & "', ChangedOn = '" & ChangedOn1 & "'" & _
"WHERE PeopleID = & PeopleID &;"
GetUpdateTextSQL = SQLStr
//And here Im inserting and executing command below to get values from excel:
For Each r In Range("A45", Range("A45").End(xlDown))
CmdForSave.CommandText = _
GetUpdateTextSQL( _
r.Offset(0, 1).Value, r.Offset(0, 2).Value, _
r.Offset(0, 3).Value, _
r.Offset(0, 4).Value, r.Offset(0, 5).Value, _
r.Offset(0, 6).Value, r.Offset(0, 7).Value, _
r.Offset(0, 8).Value, r.Offset(0, 9).Value, _
r.Offset(0, 10).Value, r.Offset(0, 11).Value, _
r.Offset(0, 12).Value, r.Offset(0, 13).Value, _
r.Offset(0, 0).Value)
CmdForSave.Execute
Next r
The error I get is 'Incorrect Syntax near 'PIC'
What is wrong with my code? Iam using MS SQL Express (SQL 2012)
Thanks All,
I have figured it out why the problem is with space on the update SQL Statement.
The right statement using VBA (space before SET, space before WHERE):
SQLStr = _
"UPDATE People" & _
" SET PIC = '" & PIC & "', Customer = '" & Customer & "'" & _
" WHERE PeopleID = '" & PeopleID & "';"
Related
Im getting a Data type mismatch in criteria expression.
This is an update button Im trying to implement.
Access_Num is the only number(data_type) here.
I'm using MSACCESS2007
Is it a good pracrice to make all data types in the database as text?
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
cn = New OleDbConnection(con)
cn.Open()
With cmd
.Connection = cn
.CommandText = "Update [Book] SET [Book_ID] = '" & TextBox1.Text & _
"', [Access_Num] = '" &Integer.Parse(TextBox2.Text) & _
"', [Title] = '" & TextBox3.Text & _
"', [Author] = '" & TextBox4.Text & _
"', [Publisher] = '" & TextBox5.Text & _
"', [Category] = '" & ComboBox1.Text & _
"', [Contents] = '" & TextBox7.Text & _
"', [Availability] = '" & ComboBox2.Text & "' WHERE [Access_Num] = '" & Integer.Parse(TextBox2.Text) & "'"
.ExecuteNonQuery()
End With
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
'cn.Close()
'cmd.Dispose()
MsgBox("Successfully Updated")
End Sub
Your problem is that you have string delimiters everywhere. Remove them for all fields that aren't strings:
With cmd
.Connection = cn
.CommandText = "Update [Book] SET [Book_ID] = '" & TextBox1.Text & _
"', [Access_Num] = " & Integer.Parse(TextBox2.Text) & _
", [Title] = '" & TextBox3.Text & _
"', [Author] = '" & TextBox4.Text & _
"', [Publisher] = '" & TextBox5.Text & _
"', [Category] = '" & ComboBox1.Text & _
"', [Contents] = '" & TextBox7.Text & _
"', [Availability] = '" & ComboBox2.Text & "' WHERE [Access_Num] = " & Integer.Parse(TextBox2.Text)
.ExecuteNonQuery()
End With
Note that a better way would be to use parameters for the query, since that also avoids SQL injection.
Is it a good pracrice to make all data types in the database as text?
No, certainly not! That's an awful practice. Data types should represent the data stored in the column, and be the smallest practical type to represent that data.
I need help figuring out why I'm getting this syntax error when trying to run this code in Microsoft Access. I am working on this database for work and have some experience with it, but not a whole lot.
I created a database before the one I'm currently working on and it works fine. It is very similar to the database that I'm working on now, so I just copied it and then renamed the fields and text boxes and everything to match the information that this database will be handling.
Essentially I have a table with the data and then I want a form that has a text box for each field in the table with a subtable of the main table incorporated into the form. The user fills in the text boxes with the information and then either adds it to the table or they can click on a record and edit it or delete it with the corresponding buttons on the form.
Now I'm getting a runtime error '3134': syntax error in INSERT INTO statement when trying to click the add button on one of my forms. This only happens on the add button and consequently the update button if it is set to update, but all of the other buttons work fine.
Here is the code for the new database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtICN.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblInventory(ICN, manu, model, serial, desc, dateRec, dateRem, dispo, project, AMCA, UL, comments) " & _
" VALUES(" & Me.txtICN & ", '" & Me.txtManu & "', '" & Me.txtModel & "', '" & Me.txtSerial & "', '" & Me.txtDesc & "', '" & Me.txtDateRec & "', '" & Me.txtDateRem & "', '" & Me.txtDispo & "', '" & Me.txtProject & "', '" & Me.txtAMCA & "', '" & Me.txtUL & "', '" & Me.txtComments & "')"
Else
'otherwise (Tag of txtICN store the ICN of item to be modified)
CurrentDb.Execute "UPDATE tblInventory " & _
" SET ICN = " & Me.txtICN & _
", manu = '" & Me.txtManu & "'" & _
", model = '" & Me.txtModel & "'" & _
", serial = '" & Me.txtSerial & "'" & _
", desc = '" & Me.txtDesc & "'" & _
", dateRec = '" & Me.txtDateRec & "'" & _
", dateRem = '" & Me.txtDateRem & "'" & _
", dispo = '" & Me.txtDispo & "'" & _
", project = '" & Me.txtProject & "'" & _
", AMCA = '" & Me.txtAMCA & "'" & _
", UL = '" & Me.txtUL & "'" & _
", comments = '" & Me.txtComments & "'" & _
" WHERE ICN = " & Me.txtICN.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmInventorySub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtICN = ""
Me.txtManu = ""
Me.txtModel = ""
Me.txtSerial = ""
Me.txtDesc = ""
Me.txtDateRec = ""
Me.txtDateRem = ""
Me.txtDispo = ""
Me.txtProject = ""
Me.txtAMCA = ""
Me.txtUL = ""
Me.txtComments = ""
'focus on ID text box
Me.txtICN.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtICN for reset new
Me.txtICN.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this item?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblInventory " & _
"WHERE ICN =" & Me.frmInventorySub.Form.Recordset.Fields("ICN")
'refresh data in list
Me.frmInventorySub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmInventorySub.Form.Recordset
Me.txtICN = .Fields("ICN")
Me.txtManu = .Fields("manu")
Me.txtModel = .Fields("model")
Me.txtSerial = .Fields("serial")
Me.txtDesc = .Fields("desc")
Me.txtDateRec = .Fields("dateRec")
Me.txtDateRem = .Fields("dateRem")
Me.txtDispo = .Fields("dispo")
Me.txtProject = .Fields("project")
Me.txtAMCA = .Fields("AMCA")
Me.txtUL = .Fields("UL")
Me.txtComments = .Fields("comments")
'store id of item in Tag of txtICN in case ICN is modified
Me.txtICN.Tag = .Fields("ICN")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
And here is the code for the old database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblEquipmentList(equipID, equipDesc, equipManu, equipModelNum, equipSerNum, lastCalDate, calDue) " & _
" VALUES(" & Me.txtID & ", '" & Me.txtDesc & "', '" & Me.txtManu & "', '" & Me.txtModelNum & "', '" & Me.txtSerNum & "', '" & Me.txtLastCalDate & "', '" & Me.txtCalDueDate & "')"
Else
'otherwise (Tag of txtID store the id of equipment to be modified)
CurrentDb.Execute "UPDATE tblEquipmentList " & _
" SET equipID = " & Me.txtID & _
", equipDesc = '" & Me.txtDesc & "'" & _
", equipManu = '" & Me.txtManu & "'" & _
", equipModelNum = '" & Me.txtModelNum & "'" & _
", equipSerNum = '" & Me.txtSerNum & "'" & _
", lastCalDate = '" & Me.txtLastCalDate & "'" & _
", calDue = '" & Me.txtCalDueDate & "'" & _
" WHERE equipID = " & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmEquipmentListSub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtID = ""
Me.txtDesc = ""
Me.txtManu = ""
Me.txtModelNum = ""
Me.txtSerNum = ""
Me.txtLastCalDate = ""
Me.txtCalDueDate = ""
'focus on ID text box
Me.txtID.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtID for reset new
Me.txtID.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this piece of equipment?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblEquipmentList " & _
"WHERE equipID =" & Me.frmEquipmentListSub.Form.Recordset.Fields("equipID")
'refresh data in list
Me.frmEquipmentListSub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmEquipmentListSub.Form.Recordset
Me.txtID = .Fields("equipID")
Me.txtDesc = .Fields("equipDesc")
Me.txtManu = .Fields("equipManu")
Me.txtModelNum = .Fields("equipModelNum")
Me.txtSerNum = .Fields("equipSerNum")
Me.txtLastCalDate = .Fields("lastCalDate")
Me.txtCalDueDate = .Fields("calDue")
'store id of equipment in Tag of txtID in case id is modified
Me.txtID.Tag = .Fields("equipID")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
As you can see, I'm pretty confident that they're pretty much identical except for the field names.
I'm also linking an album of screenshots of the database here: http://imgur.com/a/xLV3Q
Thanks for any help you guys can provide.
The problem may be:
Your new table tblInventory has a column DESC which is a SQL reserved keyword. You have two options:
Drop the column DESC and create a new column with different name OR;
Add brackets to your script like this: INSERT INTO tblInventory([ICN], [manu], [model], [serial], [desc], [dateRec], [dateRem], [dispo], [project], [AMCA], [UL], [comments]).
Please check a full list of SQL reserved keywords: Reserved Keywords-Transact-SQL
I have a set of data that I upload to SQL and since a couple of new columns have been added (abandoned IVR & answered IVR) it is failing to upload properly.
The data will now only land in the temp table and not the full data one, but what makes it all the more confusing is that it's saying their is a syntax error of ',' on the bottom line which is blank
This is my merge statement which is when I debug is saying where the potential error is. But I don't understand why the error is pointing at a blank row and stopping the upload from happening?
Could anyone give me any pointers, apologies for the code layout - I don't know how to set it out.
Thanks
Dan
sSQL = "MERGE [C3 ODS].Telephony AS Target USING (SELECT CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client, '" & _
" Scheme,Calls_Offered,Calls_Answered,Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime, '" & _
" Average_AbandonTime,Average_SpeedAnswer,TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7, '" & _
" TimePeriod8,TimePeriod9,Abandon1,Abandon2,Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2, '" & _
" Answered3,Answered4,Answered5,Answered6,Answered7,Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section, '" & _
" ForecastGroup,AbandonedIVR,AnsweredIVR FROM [C3 ODS].Telephony_Temp) AS Temp " & _
" ON Target.CallDate = Temp.CallDate AND Target.Telephony_Lookup = Temp.Telephony_Lookup WHEN MATCHED THEN UPDATE SET Target.Calls_Offered = Temp.Calls_Offered, '" & _
" Target.Calls_Answered = Temp.Calls_Answered, Target.Calls_Abandoned = Temp.Calls_Abandoned, Target.Calls_Abandoned_SLA = Temp.Calls_Abandoned_SLA, '" & _
" Target.Calls_Answered_SLA = Temp.Calls_Answered_SLA, Target.Average_TalkTime = Temp.Average_TalkTime, Target.Average_ACW = Temp.Average_ACW, '" & _
" Target.Average_HandleTime = Temp.Average_HandleTime, Target.Average_AbandonTime = Temp.Average_AbandonTime, Target.Average_SpeedAnswer = Temp.Average_SpeedAnswer, '" & _
" Target.VDN_Name = Temp.VDN_Name, Target.Skill_Name = Temp.Skill_Name, Target.Site = Temp.Site, Target.Team = Temp.Team, Target.SubTeam = Temp.SubTeam, '" & _
" Target.ClientGroup = Temp.ClientGroup, Target.Client = Temp.Client, Target.Scheme = Temp.Scheme " & _
" WHEN NOT MATCHED THEN INSERT (CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client,Scheme,Calls_Offered,Calls_Answered, '" & _
" Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime,Average_AbandonTime,Average_SpeedAnswer, '" & _
" TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7,TimePeriod8,TimePeriod9,Abandon1,Abandon2, '" & _
" Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2,Answered3,Answered4,Answered5,Answered6,Answered7, '" & _
" Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section,ForecastGroup,AbandonedIVR,AnsweredIVR) " & _
" VALUES (Temp.CallDate, Temp.VDN, Temp.VDN_Name, Temp.Skill, Temp.Skill_Name, Temp.Telephony_Lookup, Temp.Site, Temp.Team, Temp.SubTeam, '" & _
" Temp.Client, Temp.Scheme, Temp.Calls_Offered, Temp.Calls_Answered, Temp.Calls_Abandoned, Temp.Calls_Abandoned_SLA, Temp.Calls_Answered_SLA, '" & _
" Temp.Average_TalkTime, Temp.Average_ACW, Temp.Average_HandleTime, Temp.Average_AbandonTime, Temp.Average_SpeedAnswer, Temp.TelephonySystem, '" & _
" Temp.TimePeriod1, Temp.TimePeriod2, Temp.TimePeriod3, Temp.TimePeriod4, Temp.TimePeriod5, Temp.TimePeriod6, Temp.TimePeriod7, Temp.TimePeriod8, '" & _
" Temp.TimePeriod9, Temp.Abandon1, Temp.Abandon2, Temp.Abandon3, Temp.Abandon4, Temp.Abandon5, Temp.Abandon6, Temp.Abandon7, Temp.Abandon8, '" & _
" Temp.Abandon9, Temp.Abandon10, Temp.Answered1, Temp.Answered2, Temp.Answered3, Temp.Answered4, Temp.Answered5, Temp.Answered6, Temp.Answered7, '" & _
" Temp.Answered8, Temp.Answered9, Temp.Answered10, Temp.DataLoad_Date, Temp.ClientGroup, Temp.LOB, Temp.ServiceLevel, Temp.Section, '" & _
" Temp.ForecastGroup, Temp.AbandonedIVR, Temp.AnsweredIVR);"
Cn.Execute sSQL
I'm working with an SQL Server and I'm create a program to add records to the database. However, the database's field for the Dates of Births isn't being accepted.
At the server side, the data type is 'Date' on MS Express SQL Server that should be YYYY-MM-DD. However, when trying to 'upload' the new records from the program the dates are being rejected. I know it's down to how I'm formatting them and particularly I know it's literally just two lines of code; But I can't get it going!
SQL = "Insert into PersonsA(Members_ID," & _
"Gamer_Tag," & _
"Screenname," & _
"First_Name," & _
"Last_Name," & _
"DoB," & _
"E_Mail_Address," & _
"Position," & _
"U_G_Studio," & _
"Cautions," & _
"Record," & _
"Event_Attendance," & _
"Member_Status) values('" & Me.midtxt.Text.Trim & "'," & _
"'" & Me.gttxt.Text.Trim & "'," & _
"'" & Me.sntxt.Text.Trim & "'," & _
"'" & Me.fntxt.Text.Trim & "'," & _
"'" & Me.lntxt.Text.Trim & "'," & _
"" & Val(Me.dobtxt.Text) & "" & _ 'THIS IS THE DATES OF BIRTHS
"'" & Format(Me.dobtxt.Text, "YYYY-MM-DD") & "'," & _ 'THIS IS FORMATTING
"'" & Me.emailtxt.Text.Trim & "'," & _
"'" & Me.teamptxt.Text.Trim & "'," & _
"'" & Me.ugptxt.Text.Trim & "'," & _
"'" & Me.ugctxt.Text.Trim & "'," & _
"'" & Me.recordtxt.Text.Trim & "'," & _
"'" & Me.eventatxt.Text.Trim & "'," & _
"'" & Me.Mstattxt.Text.Trim & "')"
So as you can see the two lines I'm having trouble are:
"" & Val(Me.dobtxt.Text) & "" & _
"'" & Format(Me.dobtxt.Text, "YYYY-MM-DD") & "'," & _
I know it'll be something really stupid, but I'm newish to programming.
Reject your command string and start using SqlParameter.
Dim conn As New SqlConnection("conStr")
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "INSERT INTO [PersonsA] ([Members_ID], [Gamer_Tag]) VALUES (#Members_ID, #Gamer_Tag);"
cmd.Parameters.AddWithValue("#Members_ID", Me.midtxt.Text.Trim) '<- If Int type change to: Integer.Parse(Me.midtxt.Text.Trim)
cmd.Parameters.AddWithValue("#Gamer_Tag", Me.gttxt.Text.Trim)
conn.Open()
cmd.ExecuteNonQuery()
Date column example:
cmd.Parameters.AddWithValue("#MY_DATE_PARAM", Date.Parse(Me.dateTextBox.Text.Trim))
If cell.Value <> "" Then
uid = cell
lname = Left(Replace(Range(cell.Address).Offset(0, 1), "'", ""), 50)
fname = Replace(Range(cell.Address).Offset(0, 2), "'", "")
stat = Replace(Range(cell.Address).Offset(0, 3), "'", "")
role = Left(Replace(Range(cell.Address).Offset(0, 4), "'", ""), 50)
iqn = Replace(Range(cell.Address).Offset(0, 5), "'", "")
sdate = Format(Replace(Range(cell.Address).Offset(0, 6), "'", ""), "yyyy-mm-dd")
bdate = Format(Replace(Range(cell.Address).Offset(0, 7), "'", ""), "yyyy-mm-dd")
rodate = Format(Replace(Range(cell.Address).Offset(0, 8), "'", ""), "yyyy-mm-dd")
End If
hirereason = Replace(Range(cell.Address).Offset(0, 9), "'", "")
roreason = Replace(Range(cell.Address).Offset(0, 10), "'", "")
sql = "BEGIN TRAN IF EXISTS (SELECT * FROM " & TableName & " WITH (updlock, serializable)"
sql = sql & " WHERE UID = '" & uid & "')"
sql = sql & " BEGIN"
sql = sql & " UPDATE" & TableName
sql = sql & " SET LName='" & lname & "', FName='" & fname & "'"
sql = sql & ", Status='" & stat & "', Role='" & role & "'"
sql = sql & ", IQNRole='" & iqn & "', StartDate='" & sdate & "'"
sql = sql & ", BillableDate='" & bdate & "', RollOffDate='" & rodate & "'"
sql = sql & ", HireReason='" & hirereason & "', RollOffReason='" & roreason & "'"
sql = sql & " WHERE UID = '" & uid & "'"
sql = sql & " END"
sql = sql & " ELSE BEGIN"
sql = sql & " INSERT " & TableName & " (UID, LName, FName, Status, Role, IQNRole, StartDate"
sql = sql & ", BillableDate, RollOffDate, HireReason, RollOffReason)"
sql = sql & " VALUES('" & uid & "', '" & lname & "', '" & fname & "', '" & stat & "'"
sql = sql & ", '" & role & "', '" & iqn & "', '" & sdate & "', '" & bdate & "', '" & rodate & "'"
sql = sql & ", '" & hirereason & "', '" & roreason & "')"
sql = sql & " END COMMIT TRAN"
Cn.Execute (sql)
End If
I have some values and I'm formatting the date values which come is as string to date. If I run this as is it puts a default value for "" into the DB as 1900-1-1. I want the NULL values to actually stay in the DB and not be over-written. Furthermore I want them to update a cell with NULL if say it didn't use to be but now is.
I tried wrapping my value rodate in an IF statement and tried validating it against NULL, NOTHING, and EMPTY to say if it is one of these UPDATE DB with "NULL" but it doesn't do it. Date still comes out 1900-1-1. Any ideas?
Dim roDate
'...
'...
rodate = Trim(cell.Offset(0, 8).Value)
If len(rodate)=0 Then
rodate = null
else
rodate = "'" & Format(rodate, "yyyy-mm-dd") & "'"
end if
'....
'....
'note no single quote here around rodate
sql = sql & ", BillableDate='" & bdate & "', RollOffDate=" & rodate
'...
'...
I'm confused, not sure if I get this question right.
The only thing I understood from it is that you are struggling with saving a date as NULL in the database.
NULL and an empty string are not the same.
Try and see if this works:
dim vNull as variant
vNull = Null
if sDate = "" then
//Save vNull instead of Date
end if
I don't believe that you can capture NULL in a string datatype.
Edit
Perhaps stupid that I didn't think of this before, but instead of an empty string, can't you just put the string "NULL" in the query string?