Results 1 to 6 of 6
  1. #1
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43

    Require data in textbox

    Let's say I have a form with a textbox and a button that requeries a subform.


    How can I display a msgbox if there is no data in textbox and cancel the requery procedure ?

    Thank you in advance

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What do you have behind the Button now?

  3. #3
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    The button runs this code on Click:

    Code:
    Private Sub Command12_Click()
    On Error GoTo Command12_Click_Err
    
        DoCmd.OpenQuery "Query1", acViewNormal, acEdit
        Me.TempTable_subform.Requery
        
    
    Command12_Click_Exit:
        Exit Sub
    
    Command12_Click_Err:
        MsgBox Error$
        Resume Command12_Click_Exit
       
       End Sub

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You will need to change the code to something like:
    Code:
    Private Sub Command12_Click()
       On Error GoTo Command12_Click_Err
       DoCmd.OpenQuery "Query1", acViewNormal, acEdit
       If Len(Me.YourTextBox & "") > 0 Then
          Me.TempTable_subform.Requery
       End If
    Command12_Click_Exit:
       Exit Sub
    Command12_Click_Err:
       MsgBox Error$
       Resume Command12_Click_Exit
    End Sub
    Of course you need to use YourTextBox name instead of the one I used.

  5. #5
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Can I enter an else if to show a msgbox for the required field?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Of course.

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

Similar Threads

  1. Replies: 4
    Last Post: 12-22-2011, 03:04 AM
  2. Replies: 2
    Last Post: 08-02-2011, 07:25 AM
  3. Can queries require 4GB of ram?
    By chris@staples in forum Queries
    Replies: 3
    Last Post: 06-20-2011, 03:28 PM
  4. Replies: 4
    Last Post: 01-05-2011, 07:56 AM
  5. require help with query
    By ashiers in forum Queries
    Replies: 2
    Last Post: 04-15-2009, 08:04 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