Results 1 to 3 of 3
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    delete tempVar before creating new or overwrite

    Hi

    I have a form with two text fields and a button used to create two tempVars used in a form based on a query using the tempVars

    code is below.



    Code:
    TempVars.Add "varForename", Me.txtForename.Value
        TempVars.Add "varSurName", Me.txtsurname.Value
        DoCmd.Close acForm, "frm_BaptismForenameandSurnameSearchAll"
        DoCmd.OpenForm "frm_BaptismforenameSurnameSearchResultsAll", acNormal, "", "", , acNormal
    THis calls the other form using this query



    Code:
    SELECT tbl_Parish.Parish, tbl_Church.Church, tbl_Baptism.FicheNo, tbl_Baptism.BirthDate, tbl_Baptism.DateOfBaptism, tbl_Baptism.YearOfBaptism, tbl_Baptism.FullDateOfBaptism, tbl_Baptism.ChildsName, tbl_Baptism.Surname, tbl_Baptism.Sex, tbl_Baptism.Parents, tbl_Baptism.Abode, tbl_Baptism.Occupation, tbl_Baptism.RefNo, tbl_Baptism.PageNo, tbl_Baptism.EntryNo, tbl_Baptism.Minister, tbl_Baptism.Notes, tbl_Baptism.BaptismID
    FROM tbl_Parish INNER JOIN (tbl_Church INNER JOIN tbl_Baptism ON tbl_Church.ChurchID = tbl_Baptism.ChurchID_fk) ON tbl_Parish.ParishID = tbl_Church.ParishID_fk
    WHERE (((tbl_Baptism.ChildsName) Like [TempVars]![varForename] & "*") AND ((tbl_Baptism.Surname) Like [TempVars]![varSurname] & "*"))
    ORDER BY tbl_Baptism.FullDateOfBaptism;
    Apologies for being long winded.

    THis all worked perfectly the first time the second time you put in a forename and surname the second forms opens with no records listed it's as if the tempVars are not eing recognised. If I then close the database and reopen it all works perfectly.

    On the form

    frm_BaptismforenameSurnameSearchResultsAll

    I have two buttons

    Home - taked you back to a main menu and Search Again which takes you back to the page where you input the values for var Surname and varForename.

    The Search again Button has the code

    Private Sub btn_NewSearch_Click()
    DoCmd.Close
    DoCmd.OpenForm FormName:="frm_BaptismForenameandSurnameSearch"
    End Sub[/CODE]

    My thought is to add some code to delete the two variable? I thought they would be overwritten with any new values

    Would as usual appreciate any thoughts

    thanks

    Ian

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    It is a good practice to remove TempVar object variables when you are finished using them.

    tempvars.removeall removes them all

  3. #3
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    THanks

    I'll have a look later - on baby sitting duties at moment for World Book Day- looking after a Gruffalo :-)

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

Similar Threads

  1. Replies: 4
    Last Post: 12-13-2016, 09:48 AM
  2. tempvar issue
    By Jen0dorf in forum Access
    Replies: 2
    Last Post: 04-24-2016, 03:37 AM
  3. Replies: 7
    Last Post: 04-29-2015, 10:57 AM
  4. Creating a delete query
    By mmcgibbony in forum Queries
    Replies: 4
    Last Post: 09-22-2014, 11:17 AM
  5. How do you overwrite a table created in VBA? [DELETE]
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-20-2011, 02:22 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