Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

written in Acess Visual Basic This code only inserts one record into the table.

ID: 3688340 • Letter: W

Question

written in Acess Visual Basic

This code only inserts one record into the table. It should insert until the loop is finished. What is wrong?

Private Sub btnEnterDates_Click()

Dim maxdate As Date

Dim daystoadd, diff As Integer

Dim strSQL As String

maxdate = DMax("Work_Date", "WorkDate")

daystoadd = Me.txtAddDays.Value

diff=0

While daystoadd > diff

maxdate = DateAdd("d", 1 , maxdate)

strSQL = " INSERT INTO Workdate(Work_Date) VALUES('maxdate')"

DoCmd.SetWarnings False

DoCmd.RunSQL strSQL

DoCmd.SetWarnings True

diff = diff + 1

Wend

Explanation / Answer

Private Sub createRec_Click() Dim StrSQL As String Dim InDate As Date Dim DatDiff As Integer Dim db As database InDate=Me.FromDateTxt 'here I have used a code to find out the difference between two dates that i've not written For i = 1 To DatDiff StrSQL = "INSERT INTO Test (Start_Date) VALUES ('" & InDate & "' );" StrSQL = StrSQL & "SELECT 'Test'" db.Execute StrSQL db.close