Originally Posted by
orange
Thank you, that was very, very, very helpful!
I do have a question tho, that even after reading SQL and vba that still have me baffled. I am looking at another persons code. I did not write it, just trying to understand it.
What I am completely baffled is how it works, each and every time.
Code:
Private Sub Command29_Click()
Dim rsc As Recordset
Dim ClassNmb As Long
'DoCmd.Beep
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT DISTINCTROW " & _
"Employees.Department, Employees.Title, Employees.LastName, " & _
"Employees.FirstName, Employees.[Employee Number], Employees.[Original Hire Date] " & _
"INTO WrkTable FROM Employees " & _
"ORDER BY Employees.Department, Employees.Title, Employees.LastName, Employees.FirstName;"
DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN Chosen Logical;"
DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN CourseNumber Long;"
DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN Attended Logical;"
DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN DateAttended Date;"
DoCmd.RunSQL "UPDATE WrkTable " & _
"SET WrkTable.CourseNumber = Forms!EdClasses!CourseNumber.Value;"
DoCmd.OpenForm "EdEnroll"
DoCmd.SetWarnings True
End Sub
After reading the tutorial, shouldn't this code fail the second time you run it since the four columns have already been added?