Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Searching for Null


Message #1 by "Christopher Mohr" <cmohr@b...> on Thu, 24 Oct 2002 23:26:09
What I am trying to do is have a text box with a number value.
I want to set up a seperate form with that will look for the text box 
value in the table and if there is a matching value then show a button on 
the seperate form, however if there is no match then I want to hide the 
button on the seperate form.

Is this possible?

Thanks,

Chris
Message #2 by "Bob Bedell" <bobbedell15@m...> on Fri, 25 Oct 2002 06:01:23 +0000
Hi Chris,

I'm not sure I have this right but...

Form1 is open. Form1 has a text box on it. The text box has a value in
it.

You open Form2. Form2 has a command button on it. You want to
search a table for the value in the text box on Form1 and then either
hide or show the button on Form2 based on the result of the search.

I added a second command button to Form2, set its visible property
to false, and pasted the following code in its click event:

Sub cmdSearch_Click()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim intNumber As Integer
    Dim strCriteria As String
    Dim intResponse As Integer

    intNumber = Forms!Form1!txtSearch.Text
    strCriteria = "[SearchNumber]=' " & intNumber & "'"

    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    rst.Open "tblTest", cnn, adOpenStatic, adLockReadOnly

    With rst
        .Find strCriteria
        If Not .EOF Then
            intResponse = MsgBox("Value found. " _
               & "Do you want to show cmdHide?", vbYesNo)
            If intResponse = vbYes Then
                Me.cmdHide.Visible = True
            End If
        Else
            MsgBox "Value not found."
        End If

        .Close
    End With

End Sub

'~~~~~~~~~~Stop~~~~~~~~~~

Any way, that's how to use the Find method of an ADO recordset object to
search a recordset. If end-of-file condition evaluates to true, your
search criteria wasn't found. Be careful with the quotation marks
in the Find method argument. The syntax is a little tricky. tblTest
has one field, SearchNumber, with five records (1-5).

>From: "Christopher Mohr" <cmohr@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Searching for Null
>Date: Thu, 24 Oct 2002 23:26:09
>
>What I am trying to do is have a text box with a number value.
>I want to set up a seperate form with that will look for the text box
>value in the table and if there is a matching value then show a button on
>the seperate form, however if there is no match then I want to hide the
>button on the seperate form.
>
>Is this possible?
>
>Thanks,
>
>Chris


_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.  
http://resourcecenter.msn.com/access/plans/freeactivation.asp


  Return to Index