Hey guys,
I made a code that enables users to set an appointment in Outlook through my application and then optional select another computer to set the same appointment in.
When the other computer opens up the application, the appointments are automaticly extracted to outlook.
This works well with one appointment at a time, but i want to loop through the records untill criteria are met.
Code:
Dim strUsername As String
'FOSUserName is a function that extracts the network login name of users.
strUsername = fOSUserName()
'Look if there are records that meet criteria. When the username matches a record and the appointment is not exported yet then we move on
Dim strSQLid As String
strSQLid = "SELECT DISTINCT IDagenda FROM tblAgenda " _
& "WHERE ChoosePostBox = '" & strUsername & "' AND AfspraakGeexporteerd = False"
With CurrentDb.OpenRecordset(strSQLid)
If .RecordCount > 0 Then
'I want to loop as long as the recordcount returns greater then zero
Do Until .RecordCount > 0
Dim IntSQL As Integer
IntSQL = DLookup("IDagenda", "tblAgenda", "ChoosePostBox = '" & strUsername & "' AND AfspraakGeexporteerd = False")
With CreateObject("Outlook.Application").CreateItem(1)
.Subject = DLookup("OnderwerpAgenda", "tblAgenda", "IDAgenda = " & IntSQL & "")
.start = DateValue("" & (DLookup("DatumAgenda", "tblAgenda", "IDAgenda = " & IntSQL & "")) & "") + TimeValue("" & (DLookup("TijdAgenda", "tblAgenda", "IDAgenda = " & IntSQL & "")) & "")
.Duration = 5
.Location = DLookup("NaamPlaatsAgenda", "tblAgenda", "IDAgenda = " & IntSQL & "")
.Body = DLookup("BerichtAgenda", "tblAgenda", "IDAgenda = " & IntSQL & "")
.Save
End With
'Flag records exported to Outlook
Dim strFlagTrue As String
strFlagTrue = "Update tblAgenda set AfspraakGeexporteerd = true where IDagenda = " & IntSQL & ""
DoCmd.RunSQL strFlagTrue
'When all records are done (AfspraakGeexporteerd = true) then outta here
If .RecordCount = 0 Then Exit Do
Loop
End If
End With
I know im doing it wrong (hence i am here). Dlookup can handle only one record so i need to tab through the records.
Any pointers ?