Results 1 to 4 of 4
  1. #1
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109

    Message Box and User Input

    I am very new to VBA and I am having issues with some code. What I am trying to do is if a user clicks on a button it first gives a msgbox asking if they are sure and if they select yes it makes the user give a date. The date will be put into the [DateDestroyed] field using the mm/dd/yyyy format. I listed my code but I haven't been able to figure out how to get it to work. I haven't dealt with variables before and the compile error I am getting with the current code is variable not defined on the "Cancel =". In addition, I am not sure how to put in error checking if the user doesn't put in a date or if they put in an incorrect date (future date). Thank you for your help.



    Code:
    Private Sub destroybox_Click()
    
    If MsgBox(Prompt:="DO YOU REALLY WANT TO DO THIS?", Buttons:=vbYesNo) = vbNo Then
    Cancel = True
    Else
    [DateDestroyed] = Format (InputBox("ENTER THE DATE THE BOX WAS DETROYED", "DESTRUCTION DATE"), "mm/dd/yyyy")
    End If
    End Sub

  2. #2
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    Disregard the portion about the compile error. I forgot to put Cancel as Integer for the function "Private Sub destroybox_Click (Cancel As Integer)". Now I am getting the Compile Error "Procedure declaration does not match description of event or procedure having the same name."

  3. #3
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    Ok so I got it to compile and it works. I listed the code below. I removed the Cancel part because that was the problem (don't understand why though) and adjusted the if statement. Now I am going to fiddle around with an if statement to do the error checking. If anyone has an idea of how to do it, that would be great.


    Code:
    Private Sub destroybox_Click()  If MsgBox(Prompt:="DO YOU REALLY WANT TO DO THIS?", _
    Buttons:=vbYesNo) = vbYes Then [DateDestroyed] = Format (InputBox _
    ("ENTER THE DATE THE BOX WAS DETROYED", "DESTRUCTION DATE"), _
    "mm/dd/yyyy") 
    End If 
    End Sub

  4. #4
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    Got it to work. The code is below.

    Code:
    Private Sub destroybox_Click()
    Dim dtdest As Date
    On Error GoTo Error_Handler
    
    If MsgBox(Prompt:="DO YOU REALLY WANT TO DESTROY THE BOX? THIS WILL NOT DELETE THE BOX FROM THE RECORDS", _
    Buttons:=vbYesNo) = vbYes Then
    dtdest = InputBox("ENTER THE DATE THE BOX WAS DESTROYED", "DESTRUCTION DATE")
    While IsDate(dtdest) = False Or dtdest > Now() Or dtdest < "01/01/1975"
    MsgBox ("YOU DID NOT ENTER A DATE OR YOU ENTERED AN INVALID DATE!! TRY AGAIN...")
    dtdest = InputBox("ENTER THE DATE THE BOX WAS DESTROYED", "DESTRUCTION DATE")
    Wend
    DateDestroyed = Format(dtdest, "mm,dd,yyyy")
    Me.Requery
    Me.Refresh
    End If
    
    Error_Handler:
    On Error Resume Next
    Exit Sub
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send a message for other user
    By smahdih in forum Access
    Replies: 2
    Last Post: 11-18-2011, 01:52 PM
  2. How to take a user input
    By iamraja5 in forum Access
    Replies: 1
    Last Post: 05-12-2011, 10:17 AM
  3. Reporting with user input
    By tazbergy in forum Reports
    Replies: 1
    Last Post: 09-12-2010, 11:26 PM
  4. User Input Query
    By ManC in forum Queries
    Replies: 2
    Last Post: 03-04-2010, 07:09 PM
  5. Set required user input
    By ZeusOsiris in forum Database Design
    Replies: 2
    Last Post: 12-04-2006, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums