Using MS Access is quite new to me. I am making a leave application form where user inputs the leave date from and to then the data that will be inserted on the table should be the leave date from , then date in between from and to, and up to date. For example, leave date from 11 July up to 16 July. The data on the table should be like this: LEAVE_DATE 7/11/2016 7/12/2016 7/13/2016 7/14/2016 7/15/2016 7/16/2016
I have looked at this post How to insert values into the database table using VBA in MS access but i don't know how to do the loop for the dates.
here's my code for reference. please help me on this. thank you!
Private Sub btnSubmit_Click()
Dim FromDate As Date
Dim DateDiff As Integer
Dim strSQL As String
If Len(Nz(Trim(Me.txtLeaveFrom), "")) = 0 Then
Call MessageBox("Please enter Leave Date From.", ExclamationIcon, OKOnly)
Me.txtLeaveFrom.SetFocus
ElseIf Len(Nz(Trim(Me.txtLeaveTo), "")) = 0 Then
Call MessageBox("Please enter Leave Date To.", ExclamationIcon, OKOnly)
Me.txtLeaveTo.SetFocus
ElseIf Len(Nz(Trim(Me.cmbLeaveType), "")) = 0 Then
Call MessageBox("Please select Type of Leave", ExclamationIcon, OKOnly)
Me.cmbLeaveType.SetFocus
Else
FromDate = Me.txtLeaveFrom
strSQL = "INSERT INTO LEAVE_RECORD (EMP_ID, LEAVE_DATE, LEAVE_TYPE, APPROVED_FLG, REMARKS)" & _
"VALUES (EMPLOYEE_ID, '" & FromDate & "', '" & Me.cmbLeaveType & "' , 0, me.txtReason)"
Call MessageBox("Leave Application Submitted. Please wait for approval from management.", InformationIcon, OKOnly)
End If
End Sub