Results 1 to 4 of 4
  1. #1
    Gee is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    31

    If CheckBox True INSERT into Temp Table.

    I have a form where the user selects check boxes to choose what fields to include in a report.
    Because of the massive amount of data, I need to send it to a temp table and then on to Excel and not use a query.
    I have this line of code, for the insert into temptables for other forms that don't require the yes/no box and it works very well, but I can't figure out how to do it with these yes/no conditions.

    This is the execute line that inserts into the TempTable for the other forms:
    db.Execute "INSERT INTO TempPicktbl (Field1, Field2, Field3, Field4, Field5)" & strQuery, dbFailOnError

    How would I write: If Check1=True Then INSERT INTO TempPicktbl Field1


    If Check 2=True Then INSERT INTO TempPicktbl Field2
    If Check 3=True Then INSERT INTO TempPicktbl Field 3
    etc.

    I'm pretty sure it's the INSERT level where I need to put this code.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I would conditionally add to the SQL string (both the insert and select clauses) for each true check box.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gee is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    31
    Yes, but how would I write it?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Along these lines, from an automated import routine I happen to be working on:

    Code:
        Case "Lead Passenger Name"
          strInsert = strInsert & "LeadPassName, "
          strValues = strValues & Chr(34) & strDataAfterColon & Chr(34) & ", "
    Later on

    Code:
            strInsert = Left(strInsert, Len(strInsert) - 2)
            strValues = Left(strValues, Len(strValues) - 2)
            strSQL = "INSERT INTO tblTravelocity(" & strInsert & ") " _
                   & "VALUES(" & strValues & ")"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Temp table to prevent orphans
    By Tvanduzee in forum Database Design
    Replies: 1
    Last Post: 08-14-2012, 12:10 PM
  2. if checkbox= true subtract 8.75 from A to=B
    By VanillaAwesome in forum Queries
    Replies: 6
    Last Post: 07-28-2012, 12:48 PM
  3. delete temp table
    By slimjen in forum Queries
    Replies: 1
    Last Post: 07-19-2012, 06:35 AM
  4. Query for temp linked table
    By compooper in forum Programming
    Replies: 8
    Last Post: 06-30-2011, 06:53 AM
  5. sql temp table creation for form
    By Ian_ in forum Forms
    Replies: 2
    Last Post: 06-17-2011, 03:27 AM

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