Share via

Ms access using date function in vba code

Anonymous
2017-08-02T01:20:53+00:00

Hello sir 

    I have to restrict the data entry for previous dates unless permission is given. Date field is set to accepts dates with condition

(>=date() +1).its working well with regular entry's. Now after checking the permission for the user to entry data on any dates i didn't get the code worked. 

In vba its not accepting >, #.  Its showing error message "expected expression" 

Finally what i want is

1.If user has no permission 

Entry date = (>=date() +1)

2.if user has permission 

Entry date = (any date) 

And if necessary to be specific on (any date), it could be up to 10 days before  today. 

   Thanks in advance.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2017-08-02T13:10:07+00:00

    You haven't provided any details on what triggers "permission given". I'm not sure if the permission allows any date as you state or any date up to 10 days before today as you state.

    Assuming you have a text box [txtDate] on a form and want to change the validation rule you could use code like:

    Private Sub cmdAllowAny_Click()

        If Me.txtDate.ValidationRule <> "" Then

            Me.txtDate.ValidationRule = ""

         Else

            Me.txtDate.ValidationRule = ">=Date()+1"

        End If

    End Sub

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments