index > Visual Basic for Applications (VBA) > Restrict editing of activity based on date comparison

Restrict editing of activity based on date comparison


Hi (again!) thanks to the help of many forum members i have built a system for our users.  I have a facility that allows users to do an end of month submission and it writes the date selected into a field called 'datelastsubmitted' in 'tblusers'.  the reason i am doing this is that i do not want users to then be able to go in and edit any activity that they have entered prior to that 'datelastsubmitted' value.  When they open up an activity to edit (as opposed to creating a new one) i want to be able to restrict them from editing the activity if the 'datelastsubmitted' value is more recent than the 'activitydate' value.  this form is based on a query between linked tables so datelastsubmitted and activitydate are able to be compared

However i dont know how to get this to compare the 2 dates and then allow or disallow editing (which is done by pressing the 'activityedit' command button).

 

An example is below

(This sets the form to be non-editable by default)

Private Sub Form_Load()
Me.AllowEdits = False

End Sub

Ive then been trying to tell this button to disallow editing if the 'datelastsubmitted' value is greater than the 'activitydate' value but i guess it doesnt work this way. 

Private Sub activityedit_Click()
Dim datelastsubmitted As Date
Dim activitydate As Date
If "#Me!datelastsubmitted.value# Is >= #Me!activitydate.value#" Then _
Me.AllowEdits = False
ElseIf "#Me!datelastsubmitted.value# Is <= #Me!activitydate.value#" Then
Me.AllowEdits = True
End If
End Sub

It also tells me that there is a type mismatch on the lines "If blah blah blah blah Then"

Can anyone tell me how it should be done?

Thanks again,

Rhys.

RhysDavies

Hi Rhys,

Glad your getting there, have a look at the DateDiff method. What you can do is find the difference between the dates and if the difference is less than zero then it will mean one thing and if the difference is greater than zero then it will mean another, and if zero then they are the same. I'm being a bit generic as you can check the number of days, the number of hours, and so on and it really depends what your looking for.

Have a read of the help file as it's a powerful function, you'll find what your needing there.

Also, you can use the CDate function to convert a string containing a date to a date variable, if you needing it.




www.dsmyth.net/blog
Derek Smyth

cheers deerk - went away to sit down in a dark room and came back and got it working - cheers for the pointer.

Rhys.

RhysDavies
nice one Rhys no worries, hope you left a window open.


www.dsmyth.net/blog
Derek Smyth
reply 4

You can use google to search for other answers

 

More Articles

• Novice VBA User needs help with using data from input box for Cel...
• Using user form to create list of files to be open
• Aliases !!!
• Substitute/Replace
• format numbers in html
• ShellExecute Function
• Help finding the next similar cell and inserting rows
• OpenRecordset VBA Parameters
• export lots of Access stored queries
• Problem With Code That Writes a Change To Itself
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Program aborts only when run with Access
• VBA Excel: PivotTable Visibility and Piv
• access vba issues
• Summing on varying number of rows in Exc
• Refreshing web query that is password pr
• Problem with XP SP2
• Recursive Function
• Error Referencing DLL in VBA
• VBA Module to DLL
• Runtime Error 1004, Worksheets method er
• Access 2003 Printer Settings
• After_Save Event???
• Defining objects within a cell range
• Newbie Help: All caps to Title caps
• use Active directory to find ip address

Hot Articles

• Is VBA SDK free and ...?
• ftp using vba
• Migrate Access Forms with VBA to VB.NET
• Access Developer Extensions
• Matrix syntax
• Excel memory issues
• Summing on varying number of rows in Exc
• Deleting tabs when a cell is emptied
• Left, Mid and Right functions not workin
• Sending a variable from excel module to
• Retrieve IBM Workplace Forms data into E
• No Database Type
• Sending char to other windows controls
• Type Mismatch
• OpenRecordset VBA Parameters

Recommend Articles

• VBA Queston on Formatting Macro
• Textbox won't keep new values after work
• User Input on Range Selection
• Please Help with Access 2003 and ActiveX
• Access 2003 Printer Settings
• Setting Autonumber back to zero
• VBA SourceName method
• Is an Excel bug that Excel refuse to set
• Parsing text with tags in Excel using VBA
• Unable to create .NET class in VBA
• autocomplete
• How Ms/Access can display linked UTF-8 s
• How do I do to work with two XML files
• VBA: read/write chinese words
• won't recognize DisplayControl Property