Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    My project for tomorrow

    thanks



    Ian

  2. #17
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Quote Originally Posted by Micron View Post
    Not necessarily better, just the way I'd do it.
    That was my feeling as well. Yours has the advantage of not hitting the data twice. It has the disadvantage of having to remember to trap the 2501 error. Do you also have to reopen frm_BaptismYearSearch? It looks like it would be left closed and the user left in limbo, or at least with no results and having to reopen the search form to search again.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Quote Originally Posted by pbaldy View Post
    Yours has the advantage of not hitting the data twice. It has the disadvantage of having to remember to trap the 2501 error. Do you also have to reopen frm_BaptismYearSearch? It looks like it would be left closed and the user left in limbo, or at least with no results and having to reopen the search form to search again.
    It also provides for reporting any other error, although I doubt there would be any. I wanted to intrigue the OP with error handling
    I would not close the form in the button click event either; rather in the form open event if there were > 0 records, but only if I knew I would not want to run another search after the last one. Why not let the user close the form with a button when they're good and done?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #19
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    THanks both,

    I'll look tomorrow - have to move onto my wifes project - family history research in the US

    Ian

  5. #20
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Late in posting, but I had the construct that Paul suggested.

    Code:
    '------------------------------------------------------------
    ' btn_Search_Click
    '
    '------------------------------------------------------------
    Private Sub btn_Search_Click()
    
     TempVars.Add "varYear", Me.txtYearOfBaptism.Value
        If DCount("*", "tbl_Baptism", "YearOfBaptism= '" & Me.txtYearOfBaptism & "'") > 0 Then
    
            DoCmd.Close acForm, "frm_BaptismYearSearch"
            DoCmd.OpenForm "frm_BaptismYearSearchResults", acNormal, "", "", , acNormal
        Else
            DoCmd.OpenForm "frm_Noresults"
        End If
    End Sub

  6. #21
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    wild cards

    Hi

    Many thanks for all the suggestions, spent the day implementing them and I have now grasped some concepts.

    I ended up using
    Code:
    ------------------------------------------------------------
    ' btn_Search_Click
    '
    '------------------------------------------------------------
    Private Sub btn_Search_Click()
    
     TempVars.Add "varYear", Me.txtYearOfBaptism.Value
        If DCount("*", "tbl_Baptism", "YearOfBaptism= '" & Me.txtYearOfBaptism & "'") > 0 Then
    
            DoCmd.Close acForm, "frm_BaptismYearSearch"
            DoCmd.OpenForm "frm_BaptismYearSearchResults", acNormal, "", "", , acNormal
        Else
            DoCmd.OpenForm "frm_Noresults"
        End If
    End Sub
    Because I did like it's simplicity ( probably not a good choice of words) in that I could follow the logic.

    I now want to apply the same principle top some other forms , which I have done and they all work

    but ( ok there is always a but;-

    the results form that opens is based on a query containing a wild card

    Code:
    Like [TempVars]![varBrideForenames] & "*"
    When I implement the Dcount code it looses it's wild card component in the results, so a look at the code showed

    "*" in the query and "'" in the Dcount code.

    Ah Ha I said and changed the ' to a *

    Sucess I thought!! I thought wrong ;-(

    Did a search for "'" in google but no results to explain

    thanks

    Ian

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  2. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  3. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  4. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  5. Replies: 2
    Last Post: 06-23-2012, 11:59 PM

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