Hi, I am having an issue with getting the value of a date field on a form.
Depending on the variable type I declare I get an error when using the .GetValue method, or later when trying to put it in a string. I am at a loss as to where to go from here so any help appreciated. If more details are required let me know!
Sub AddJobLabour(oEvent as Object)
Dim Job_Number As String
Dim LabourType as String
Dim LabourStaff as String
Dim sSQL As String
Dim LabourHours As Double
Dim BlankFields as Boolean
Dim oStatement As Object
Dim LabourDate as Object
'Wont work if set as date or string.
Dim oForm As Object
Dim oField As Object
Dim oButton As Object
BlankFields = False
oForm = ThisComponent.Drawpage.Forms.getByName("Job_Add_Labour")
oField = oForm.getByName("Job_No")
Job_Number = oField.getCurrentValue
oField = oForm.getByName("Labour_Date") ' This is a date field on the form
LabourDate = oField.getCurrentValue
'error here if LabourDate is set to Date or String.
oField = oForm.getByName("txtHours")
LabourHours = oField.getCurrentValue
oField = oForm.getByName("LabourTypeList")
LabourType = oField.getCurrentValue
oField = oForm.getByName("LabourStaffList")
LabourStaff = oField.getCurrentValue
'Ensure no blank fields
if IsEmpty(Job_Number) then
MsgBox "Job Number is Empty"
BlankFields = True
endif
if IsEmpty(LabourDate) then
MsgBox "Item Number is Empty"
BlankFields = True
endif
if LabourHours<=0 then
MsgBox "Qty must be positive"
BlankFields = True
endif
if LabourType = "" then
MsgBox "Item Number is Empty"
BlankFields = True
endif
if LabourStaff = "" then
MsgBox "Item Number is Empty"
BlankFields = True
endif
' Returns True
if BlankFields = False then
sSQL = "INSERT INTO ""Job_Labour""(""Job_Number"",""Date"",""Staff_Member"",""Labour_Type"",""Actual_Hours"")VALUES('" & Job_Number & "','" & LabourDate &"','" & LabourStaff & "','" & LabourType & "','" & Labour_Hours & "')"
' fails to make SQL statement as object not string.
if IsNull(ThisDatabaseDocument.CurrentController.ActiveConnection) then
ThisDatabaseDocument.CurrentController.connect
endif
oStatement = ThisDatabaseDocument.CurrentController.ActiveConnection.createStatement()
oStatement.execute(sSQL)
oForm = ThisDatabaseDocument.FormDocuments.getByName("Job_Add_Items")
End if
iJobID = Job_Number
msgbox "Job ID : " & iJobID
FormChangeClose("Job_Detail")
End Sub