Results 1 to 2 of 2
  1. #1
    rlsublime is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    58

    VBA code to require user to enter a Value

    I am trying to edit the following code to be able to require the user to enter a Loan number and keep prompting the user to enter a value as long as the field is blank. Once the field is filled in, then the code should go on to check if the sql condition is met and make the necessary change if met, then finally, I have a save command code that will require the user to save the record. Right now I am getting errors when I added the code to require the user to enter a field. I am new to loop and if statements in vba so I am not exactly sure how to structure it. Thanks for you help.



    Code:
    Private Sub Save_Record_Click()
     
      Dim SQL As String
    Do
      If IsNull(Me![Loan Number]) Then MsgBox "Please Enter Loan Number. This is a required field."
    End If
     
    Loop Until (Me![Loan Number]) = .Value
     
    SQL = "Update Investor_Request set Status = 'Closed' where Loan_Number = " & Me![Loan Number] & _
      " AND status = 'Outstanding'"
     
     
    CurrentDb.Execute SQL, dbFailOnError
     
    On Error GoTo Err_Save_Record_Click
     
     
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
     
    Exit_Save_Record_Click:
        Exit Sub
     
    Err_Save_Record_Click:
        MsgBox Err.Description
        Resume Exit_Save_Record_Click
    
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Delete the End If line.

    Is [Loan Number] text or number datatype?

    Run Debug>Compile.

    .Value should error. This is the value of what?

    Maybe should be more like
    Loop Until Not IsNull(Me![Loan Number])

    Step debug.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 0
    Last Post: 11-22-2011, 09:10 PM
  2. Ignore user input while code is running
    By Bigdoggit in forum Forms
    Replies: 5
    Last Post: 03-28-2011, 07:58 AM
  3. Replies: 1
    Last Post: 06-10-2010, 10:47 AM
  4. Replies: 3
    Last Post: 04-07-2010, 11:25 AM
  5. Replies: 2
    Last Post: 03-02-2010, 01:58 AM

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