VBA Code:
Sub AddEntry()
Dim sh As Worksheet
Dim iRow As Long
Dim LastRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2).NumberFormat = "@"
.Cells(iRow, 2) = frmForm.txtDate2.Value
.Cells(iRow, 3) = frmForm.txtHCNumber3.Value
.Cells(iRow, 4) = frmForm.txtName4.Value
.Cells(iRow, 5).NumberFormat = "@"
.Cells(iRow, 5) = frmForm.txtDOB5.Value
.Cells(iRow, 6) = frmForm.txtAge6.Value
.Cells(iRow, 7) = frmForm.cmbSourceReferral7.Value
.Cells(iRow, 8) = frmForm.cmbSPA8.Value
.Cells(iRow, 9).NumberFormat = "@"
.Cells(iRow, 9) = frmForm.txtConsultDate9.Value
.Cells(iRow, 10) = frmForm.txtTimeR10.Value
.Cells(iRow, 11) = frmForm.cmbStatus11.Value
.Cells(iRow, 12) = frmForm.txtTimeSeen12.Value
.Cells(iRow, 13) = frmForm.cmbVisitOutcome13.Value
.Cells(iRow, 14) = frmForm.txtTimeD14.Value
.Cells(iRow, 15) = frmForm.cmbConsultant15.Value
.Cells(iRow, 16) = frmForm.txtResident16.Value
.Cells(iRow, 17) = frmForm.txtDiscussed17.Value
.Cells(iRow, 18) = IIf(frmForm.optFemale.Value = True, "Female", "Male")
.Cells(iRow, 19) = frmForm.cmbNation19.Value
.Cells(iRow, 20) = frmForm.cmbPolice20.Value
.Cells(iRow, 21) = frmForm.cmbKnown21.Value
.Cells(iRow, 22) = frmForm.cmbSuicide22.Value
.Cells(iRow, 23) = frmForm.txtReferred23.Value
.Cells(iRow, 24) = frmForm.txtRemarks24.Value
.Cells(iRow, 25) = Application.UserName
.Cells(iRow, 26) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
.Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))
End With
Code Above .Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))
i want to make it like this
or any suggestion to make it work.if frmForm.txtTimeD14.Value = 0 "no value" go to Calculate Now Date
Calculate Now Date
.Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))
end if
if frmForm.txtTimeD14.Value = with value go to Calculate time discharged.
Calculate time discharged
.Cells(iRow, 27) = (DateValue(frmForm.txtDate2.Value) + TimeValue(frmForm.txtTimeD14.Value) - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value)) * 24