Results 1 to 11 of 11
  1. #1
    pradeep.sands is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    49

    Question adding new column to recordset

    Hi all,


    I have a recordset built from a query (and this query is very complex and made from several tables).
    Ok, now my problem is, I need to add one Boolean column which is not related to any table to this recordset. Anybody can help me with this?
    Thanks

  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,598
    Fields can be constructed with expressions. What do you want this field to calculate so that result is either Yes or No?
    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
    pradeep.sands is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    49

    Question

    Hi,
    Thanks for your reply. Well, here I explain what I am exactly looking for.
    Like I said, I have a recordset built from a query (and this query is a complex one made from several other tables). Below you can see this query (i completely modified the original).
    Click image for larger version. 

Name:	Unbenannt1.JPG 
Views:	21 
Size:	20.6 KB 
ID:	12960

    Please note that there is NO primary key here.
    the first two records are same. But the query shows in two seperate records because the Machine ID is different. And similar is the case with other 4 records. they r same but refer to different machines (1,2,3,4).
    Now, I copied this query (using DoCmd) into another temporary Query and here I used 'DISTINCT' to the 'partRefNum' and hidden the MachineID field. So my new query looks like this:

    Click image for larger version. 

Name:	Unbenannt2.JPG 
Views:	21 
Size:	13.5 KB 
ID:	12961

    Now, like I asked in previous post, I need to add new fields to this query (which are Boolean) that should look like this:

    Click image for larger version. 

Name:	Unbenannt3.JPG 
Views:	21 
Size:	18.7 KB 
ID:	12962

    If you see the relation of fields of this query with the first query, the MachineID field in first query (that is creating multiple records) is now converted into different fields instead. So that multiple records are eliminated.

    So, can you help me how do I implement this?

  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,598
    You could try using the first query as the source for a CROSSTAB. The Machine fields won't be checkboxes, they will have a count of how many records related to each machine, according to the grouping you set. In this case, the group is defined by 5 fields.

    As long as there is at least one record for each machine, the crosstab will result in a column for each machine.
    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
    pradeep.sands is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    49
    @June7: Could you please eloborate it in more detail..i'm confused with the description.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Use the query wizard for CROSSTAB. Access Help has guidelines on building CROSSTAB query.
    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.

  7. #7
    pradeep.sands is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    49
    @June7: Thanks again. Now i understand. But w.r.t. your previous answer, I want a boolean/checkbox for Machine in column and not the count of records like u mentioned.
    So is there any alternative for this?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Lightbulb

    PMFJI,

    You can't really define a column as a particular type (at least I haven't been able to find a way). And a check box is a control on a form or report.

    But I create "fake" crosstab queries; the only thing is that the number of crosstab fields is fixed, unlike a normal crosstab that can adjust to the number of values in the column. In this case, my "faked" crosstab is fixed at 4 (see the formulas). If the number of machine IDs increases to 6, you would have to modify the queries, form and reports that use the machine ID.

    The easiest way to explain this is to look at the example mdb (A2000). The two queries are "Query1" and "Query1_Fake_Crosstab".

    Warning: If you have two records that are identical
    Code:
    PartRefNum     Desc     ValA        ValB        ValC   Machine_ID
       1           abcd       20          30          40         3
       1           abcd       20          30          40         3
    the result will be -2, not -1. I have not found any way around this.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    No, not directly in the CROSSTAB query. CROSSTAB query is not editable. Why is checkbox critical?

    Might be able to bind the CROSSTAB to a form or report. Convert the machine counts to a True/False (-1/0) value with an expression and bind those calculated fields to checkbox controls.
    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.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Convert the machine counts to a True/False (-1/0) value
    @June,
    You probably already know this, but here is a technique I use when I have a number field, but I just want to show true or false. (no conversion required)

    False is defined as zero.
    True is actually defined as not zero. So any non zero number is true.

    On a form what has a text box bound to a number field, add a check box bound to the same field as the text box.

    Enter a zero in the text box. The check box should be unchecked.
    Enter -1 in the text box. The check box should be checked.
    Enter a zero in the text box. The check box should be unchecked.
    Enter 3,000 in the text box. The check box should be checked.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Might have been aware of that at some time but didn't recall. If the true CROSSTAB approach is taken will still need an expression to convert the nulls to 0.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-03-2013, 11:51 AM
  2. Adding labels in new column
    By Hello World in forum Queries
    Replies: 1
    Last Post: 10-13-2011, 08:57 AM
  3. Replies: 3
    Last Post: 09-28-2011, 04:29 PM
  4. Skip column in recordset
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 02-28-2011, 12:14 PM
  5. Adding a lookup to a column
    By revnice in forum Access
    Replies: 4
    Last Post: 08-16-2010, 12:58 PM

Tags for this Thread

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