Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a text box on a form (txtLast) that is used to obtain characters of a person's last name to pass to a form/query. I have a command button/on click event with which I am trying to:
    1) test for null, and if null invoke a message box asking if the user wants to proceed with no information entered into txtLast (if null the search will return many records and I want to provide an out for the user if this was clicked inadvertently).
    2) if txtLast in not null, continue on with opening the defined form/query.
    3) if the user clicks ok, continue on.
    4) if the user clicks cancel, cancel.

    The following works with the msgbox functionality but not if txtLast is not null. In that case it does nothing. Would it be more appropriate to use before update to test for null separately? Hope this makes sense.

    Private Sub Command12_Click()
    On Error GoTo Err_Command12_Click
    If IsNull(Me.txtLast) Then
    If MsgBox("No search information entered...click ok if you wish to continue.", vbOKCancel, "Health Quest Visit Archive") = vbOK Then
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmSelectFromPatients"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Else
    Exit_Command12_Click:
    Exit Sub
    Err_Command12_Click:
    MsgBox Err.Description
    Resume Exit_Command12_Click
    End If
    End If
    End Sub
    ********
    Any help would be appreciately. Thank you.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    A couple of things. You should try to put all your variable declarations at the top of the sub. Don't wrap you Exit and Error Handling code within the IF statement.

    Code:
    	Dim stDocName As String
    	Dim stLinkCriteria As String
    
    	On Error GoTo Err_Command12_Click
    	If IsNull(Me.txtLast) Then
    		If MsgBox("No search information entered...click ok if you wish to continue.", vbOKCancel, "Health Quest Visit Archive") = vbCancel Then
    			 Exit Sub
    		End If
    	End if
    	stDocName = "frmSelectFromPatients"
    '	stCriteria =   ?what,you never specified
    	DoCmd.OpenForm stDocName, , , stLinkCriteria
    Exit_Command12_Click:
      Exit Sub
    Err_Command12_Click:
      MsgBox Err.Description
      Resume Exit_Command12_Click
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Mark. That fixed it. I appreciate the help.

    [quote name='MarkLiquorman' post='788162' date='09-Aug-2009 15:33']A couple of things. You should try to put all your variable declarations at the top of the sub. Don't wrap you Exit and Error Handling code within the IF statement.

    Code:
    	Dim stDocName As String
    	Dim stLinkCriteria As String
    
    	On Error GoTo Err_Command12_Click
    	If IsNull(Me.txtLast) Then
    		If MsgBox("No search information entered...click ok if you wish to continue.", vbOKCancel, "Health Quest Visit Archive") = vbCancel Then
    			 Exit Sub
    		End If
    	End if
    	stDocName = "frmSelectFromPatients"
    '	stCriteria =   ?what,you never specified
    	DoCmd.OpenForm stDocName, , , stLinkCriteria
    Exit_Command12_Click:
      Exit Sub
    Err_Command12_Click:
      MsgBox Err.Description
      Resume Exit_Command12_Click
    [/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •