Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populating form from search. (A2K)

    OK, I am having one small problem. I have a form where you do all the additions to the database. It has a main for and a subfrom. Anyway I have a search feature that you can find the records and all that good stuff. What I want to do is that when I click on one of the Records in the list that comes up from your search criteria to populate the other form. Is there anyway to do this. If you need me to be more clear I can try to be.

  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

    Re: Populating form from search. (A2K)

    What you can do depends on the exact situation. Start with the form and subform. What is the recordsource for the form? Is it the full table? Then, is this list you are talking about on the same form or another form?

    Making alot of assumptions, the best way to handle this is to open a recordset based on the recordsetclone of the form. Then do a findfirst for the ID of the record from the list. Then set the bookmark of your form = the bookmark of this recordset.

    Actually, if you place a combobox on your form, one of the wizard choices is to use it to find and display a record. This basically does what I've mentioned above.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populating form from search. (A2K)

    Well here is what I have. On the Access Bible CD there is an easy search that was created by database creations. I basically built this same type of search function. The search is on it's own form. I have a form where I enter in data, so on and so forth. On that I have a button that brings up the search form. Now I can click on the Radio button depedening on what I want to search by (Publication, Title, Date) whatever. In a combo box below all the things matching what was selected above show up. When I click on one of the different choices that are provided it SHOULD populate my form. For some reason though it is not. That is the only problem I am having. Once I figure this out, I am done with my database. Thanks for the help.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Populating form from search. (A2K)

    Without seeing the exact code you are using and without knowing your specific situation, I can't tell you what is wrong. Once you have selected a record on your Search Form, you then have to find that record in your Main Form. I'm assuming the Main Form is based on recordset containing all records from the table. I'm assuming some field names here, but your code should look something like this:

    with forms!mainform.recordsetclone
    .findfirst = "RecordID=" & RecordID
    if rst.nomatch = true then
    msgbox "can't find it"
    else
    forms!mainform.bookmark = .bookmark
    end if
    end with

    docmd.close acform,"Search Form"
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populating form from search. (A2K)

    here is my code for the selection.

    Private Sub BySearchType_AfterUpdate()
    Display_Click
    End Sub

    Private Sub Display_Click()
    On Error GoTo OK_Click_Err
    If IsNull(Me.OpenArgs) Then
    MsgBox "You Cannot Display Records in the Definition Mode", 16, "Definition Mode"
    Exit Sub
    End If
    If IsNull(Me![BySearchType]) Then
    Response = MsgBox("You Did Not Select a Record to Search For", 32, "No Record Selected")
    Exit Sub
    Else
    'First Update the Definition Table with the Last Option Chosen
    Dim CurDB As Database, SQLStmt As String, GetData As Recordset
    Set CurDB = CurrentDb()
    SQLStmt = "SELECT * FROM ezs_SmartSearchDefinition WHERE SearchID = " & Chr(34) & DefEntry & Chr(34) & " and Sequence = 1"
    Set GetData = CurDB.OpenRecordset(SQLStmt, DB_OPEN_DYNASET)
    If Not GetData.EOF Then
    GetData.Edit
    GetData!LastSelectedOption = Me![TypeofSearch]
    GetData.Update
    GetData.Close
    End If
    Dim Criteria As String ' This is the argument to the FindFirst method
    Set GetData = forms(CallingForm).RecordsetClone
    'Build the criteria.
    Select Case KeyDataType
    Case "Number"
    Criteria = "[" & KeyField & "]=" & Me![BySearchType]
    Case "String"
    Criteria = "[" & KeyField & "]='" & Me![BySearchType] & "'"
    Case "Date"
    Criteria = "[" & KeyField & "]=#" & Me![BySearchType] & "#"
    End Select
    'Perform the search.
    GetData.FindFirst Criteria
    If Not GetData.NoMatch Then
    'Synchronize the form's record to the dynaset's record.
    forms(CallingForm).Bookmark = GetData.Bookmark
    End If
    GetData.Close
    'Return to Me![CallingForm] and Close the EZ Search Manager
    DoCmd.SelectObject A_FORM, CallingForm
    DoCmd.Close A_FORM, "ezs_SmartSearch"
    End If
    Exit Sub
    OK_Click_Err:
    MsgBox "Invalid Search was Found", vbCritical, "Invalid Search"
    Exit Sub


    End Sub

    Hope this helps at all.

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Populating form from search. (A2K)

    This is basically the same code I suggested. However, your code doesn't do anything if .Nomatch=True. You might want to put in a msgbox there, or just go to debug at that line of code and step-thru the code a line at a time.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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