Access With Do Until Loop PROBLEMS! Loop without Do error!

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I'm not sure of the order or syntax of what I need here.

The user intends to remove a Personal Day that they have scheduled from their calendar. The user enters a date that they have a Personal Day scheduled and pushes a button to delete it. I want to check to make sure they actually have a Personal Day scheduled on the day they input. If the date enters matches a date they have scheduled, I want to get out of the loop and continue on in the macro. If after the dates scheduled are all checked, none match the date entered, I want to tell the user, "You do not have a Personal Day scheduled on this date."

Here's what I have and I'm getting a Loop without Do error:

Dim NoPD As Recordset
Set NoPD = CurrentDb.OpenRecordset("PersDaySch")
With NoPD
Do Until .EOF
If txtAddP = [SFPersDaySch].Form![EventDate] Then
Exit Do
.MoveNext
Loop
Else
MsgBox "You do not have a Personal Day scheduled on this date."
Exit Sub
End With

Any pointers are greatly appreciated!
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I think you are missing an End If but the whole structure of the code just doesn't look right.

For example, why do you Else after Loop?
 
Upvote 0
Because I don't know what I'm doing. I'm trying to combine some pieces-parts I've read on other posts.

I last tried:
Dim NoPD As Recordset
Set NoPD = CurrentDb.OpenRecordset("PersDaySch")
With NoPD
Do Until .EOF
If txtAddP = [SFPersDaySch].Form![EventDate] Then
Exit Do
End If
If txtAddP <> [SFPersDaySch].Form![EventDate] Then
.MoveNext
End If
Loop

Else
MsgBox "You do not have a Personal Day scheduled on this date."
Exit Sub
End With
 
Last edited:
Upvote 0
I don't get why there's any need to loop at all. If you have a specific date input, find the record with a pd for that person on that date. If there isn't one, message the user, otherwise delete it.

However, I think all this could be avoided if the dates presented to the user were only dates that person had a pd. Then there's no reason to verify it. Simply provide a means to update, and maybe a confirmation message.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top