By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Delete Record based on date

P: 14
I would like to stop users from deleting the first day of the month in a form. I'm running into an error of Object Required "Set X =1". Not sure what I'm missing.

Expand|Select|Wrap|Line Numbers
  1. Dim Day As Integer
  2. Dim db As Database
  3. Dim tdf As TableDef
  4. Dim X As Integer
  5.  
  6. Set db = CurrentDb()
  7. Set tdf = db.TableDefs("tblPTO")
  8. Set X = 1
  9.  
  10. If tdf.Fields("Day") = X Then
  11.     Exit Sub
  12.  
  13. Else
  14.  
  15.     DoCmd.RunCommand acCmdSelectRecord
  16.     DoCmd.RunCommand acCmdDeleteRecord
  17.  
  18.    MsgBox ("Message goes here")
  19. End If
  20.  
Dec 2 '16 #1
Share this Question
Share on Google+
4 Replies


jforbes
Expert 100+
P: 1,107
I'm not sure what you are attempting to do here. TableDefs isn't usually used in this manner.

If you want to look up values in the table, you could use DLookup(). Or if you want to see what the Value is for the current record, you can use me!Day
Dec 3 '16 #2

PhilOfWalton
Expert 100+
P: 1,430
I agree wit jforbes.
What date fields (if any) are in your table?

In any case use X = 1, not Set X = 1

Phil
Dec 3 '16 #3

P: 14
Sorry if I didn't explain it well enough. I have a form that opens with the 1st of each month as default. If a user adds other dates, that's fine, but if they delete the 1st, this causes issues with all the reports, I need at least one date per month for it to work correctly. So, I'm trying to stop them from deleting the default date. In the form the date is named "day".
Dec 9 '16 #4

PhilOfWalton
Expert 100+
P: 1,430
Try this on the OnDelete of the record
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Delete(Cancel As Integer)
  2.     If Day(MyDate) = 1 then
  3.         Cancel = True
  4.     End If
  5. End Sub
  6.  
"MyDate" is whatever the relevant date field on your form is called.

Phil
Dec 9 '16 #5

Post your reply

Sign in to post your reply or Sign up for a free account.