473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Delete Record based on date

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
4 1695
jforbes
1,107 Expert 1GB
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
1,430 Expert 1GB
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
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
1,430 Expert 1GB
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

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

Similar topics

3
by: M Wells | last post by:
Hi All, I have a table in SQL Server 2000 that contains several million member ids. Some of these member ids are duplicated in the table, and each record is tagged with a 1 or a 2 in to...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
5
by: alanspamenglefield | last post by:
Hello group, I have an SQL statement which pulls data from a table as follows: " SELECT tblSites.sites_siteno, " & _ " tblSites.sites_sitename, " & _ " Sum(tblStockResults.stkr_result) AS...
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
3
by: phried1 | last post by:
I have created a form and inserted the following tables: Date Entered Time Entered Date Modified Time Modified Essentially how and where can I have these dates and times recorded so when the...
4
by: barkarlo | last post by:
I use check box in a form "frmworkorder" like confirmation that's record finish. How can I write code who will block edit and delete record in form when is check box confirmed.
1
by: kimmccain | last post by:
I have a form with two buttons, Completed and Pended. When the completed button is clicked, the record is moved to the completed table and the form's record is decreased by 1. When the pended...
1
by: CreativeMind | last post by:
hi all, private void dgMygrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { Button bDelete=(Button)e.Item.FindControl("btnDelete"); if(bDelete!=null) {...
5
by: agarwasa2008 | last post by:
Hi, I would like to delete a record based on a user entered string. Here are the details. I have a txtFind textbox. A string is entered by the user. Based on that string value it displays that...
13
by: SeadooRider | last post by:
I used the button wizard to set up a delete record button. It does delete a record and then moves to the next record, however I need it to ask the user first before deleting and also if it is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.