Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QueryDef Help Required

Status
Not open for further replies.

Carol57

IS-IT--Management
Nov 5, 2000
19
0
0
CA
Using the following code to populate with unique records, but I am receiving a Compile Error - Argument not Optional at the SQLOutput line, with the following code:

Private Sub Employee_AfterUpdate()

Dim dbs As Database
Dim qdfdef As QueryDef
Dim qdfTemp As QueryDef
Dim rst As Recordset

Set dbs = CurrentDb

Set qdfTemp = dbs.CreateQueryDef("")

SQLOutput "SELECT Absences.ID, Absences.Date, Absences.Details, Absences.Image, Absences.Employee"
FROM Absences
WHERE (((Absences.Employee) = [Forms]![EmployeeAbsenceCalendar]![Employee]))

qdfTemp

If Not ErrorCondition Then
m_bFoundFile = True
Else
m_bFoundFile = False
End If


If m_bFoundFile Then
If rst.RecordCount > 0 Then
rst.MoveFirst


Do While Not rst.EOF
HoldDate = rst!Date
HoldDetail = rst!Details
Me.ctCalendar1.DateText(HoldDate) = HoldDetail
Me.ctCalendar1.DateImage(HoldDate) = rst!Image


rst.MoveNext
Loop
End If
End If
Exit Sub
DBErrorHandler:
'MsgBox " Database not Found!"
ErrorCondition = True
End Sub

Function SQLOutput(strSQL As String, qdfTemp As QueryDef)

Dim rstEmp As Recordset
qdfTemp.SQL = strSQL
Set rstEmp = qdfTemp.OpenRecordset
Me.ctCalendar1 = rstEmp
rstEmp.Close

End Function

---------------------

The following code works okay if passed directly to the underlying table.

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Absences")

If Not ErrorCondition Then
m_bFoundFile = True
Else
m_bFoundFile = False
End If


If m_bFoundFile Then
If rst.RecordCount > 0 Then
rst.MoveFirst

Do While Not rst.EOF
HoldDate = rst!Date
HoldDetail = rst!Details
Me.ctCalendar1.DateText(HoldDate) = HoldDetail
Me.ctCalendar1.DateImage(HoldDate) = rst!Image


rst.MoveNext
Loop
End If
End If
Exit Sub
DBErrorHandler:
'MsgBox " Database not Found!"
ErrorCondition = True
End Sub

---------------------

Could someone please advise what I have missed.

---------------------

 
I think this is what it doesn't like:
Set qdfTemp = dbs.CreateQueryDef("")

I don't think you can create a null querydef object like this.

Try flipping around the creation of the SQL string and the creation of the queryDef.

It seems though, that you have an awful lot of code to do what appears to be a rather simple thing. Do you get paid by the word or what?.. [smile]

There should be a much easier way to do this.

Jim
Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top