Results 1 to 5 of 5
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    Creating a new field on a from by means of SQL string or some other means

    Hello. I have a question. I have a tabular form that has as its record source an SQL string. The SQL string takes its records from one table. What I would like to do is add an extra field in the tabular form (a boolean field) in the detail area of the form which does not correspond to any field in the table from which the records are drawn, but which will appear on the same level as a specific record. I want to do this so the user can check this field for desired records to select a group of the displayed records for special attention. How might I do this? Can I modify the SQL string to create an extra field just for the form which does not correspond to a field in the table from which the records come?



    Thank you in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    No, the constructed field is not editable and would show the same value for every record.

    The checkbox would have to be bound to a field, otherwise every record will show the same value
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Thank you. So if I understand you, the only way to do what I want to do would be to create a temporary table (TempTable) with the relevant fields from the
    main table plus the new Boolean field, then populate this table by means of code with the records which would have been grabbed by the form's SQL statement, and have the record source of the form be this new table instead of the SQL statement. Actually, now that I think about it, the best thing would be to include this dummy Boolean field in the original table, and have it included by the SQL statement, and then have the Form_Load have code like this...


    sub Form_Load
    Dim db as DAO.database, RST as DAO.recordset
    set db = currentdb
    set RST = db.openrecordset(me.SQL)
    do while not rst.eof
    rst.edit
    rst!dummy = false
    rst.update
    rst.movenext
    loop
    end sub

    This seems cumbersom but maybe its the best way.

    What do you think?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you want to make sure the form opens with all records set to False for the Yes/No field, try:

    Sub Form_Load()
    CurrentDb.Execute "UPDATE tablename SET dummy=False"
    Me.Refresh
    End Sub

    Is this a multi-user db?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    1) That works great, Thanks
    2) No, its not multi-user


    It doesn't add significantly to the DB size to add the Boolean field to the table, and the update command you gave me is very fast. In my sample table I have put 10,000 records, probably many times more than I will ever need, and updating the field to false in all 10,000 records occurred almost instantaneously. Thanks again!

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

Similar Threads

  1. Filter a report by means of a list box
    By bjornas in forum Modules
    Replies: 7
    Last Post: 01-03-2015, 03:16 PM
  2. Filtering records by means of Option Button
    By McArthurGDM in forum Queries
    Replies: 3
    Last Post: 08-04-2014, 05:22 PM
  3. Replies: 7
    Last Post: 06-08-2014, 03:11 PM
  4. Replies: 3
    Last Post: 08-29-2013, 02:10 AM
  5. Can someone explain what this means?
    By Jay13 in forum Access
    Replies: 5
    Last Post: 05-23-2013, 04: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