Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Use new query in form

    I have a form for jobs, a subform for work days. I have also made a query that uses the Job_ID on that form and counts how many times that ID appears in the workdays table.

    so.. a job has 2 assigned days it comes back with the number 2...

    What I want:
    the name for the day to be that value +1 automatically.

    So if no days are assigned to a job its 0+1 = Day 1
    If one day is assigned 1+1= Day 2
    and so on.

    I want this name to then be added to a textbox on the form called day_title.

    relevant info:
    query name: daycounterQ


    form: JobF
    subform: workdays


    If you need anymore info to assist just ask.

    how I think it will work:

    the generated number is displayed on the form on a hidden text box. Then some vba code will use the value of that text box and concatenate it with the work days to give us our day name.

    I have no idea how to do any of this. How would I even reference a new query on the form?

    All advice much appreciated, Andy.
    Last edited by June7; 10-21-2015 at 10:24 AM.

  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,641
    You want to assign a sequential number to records for each job? This is generating a custom unique identifier (in this case, unique for each job, not the table) - a common topic. https://www.accessforums.net/databas...try-21975.html

    Is it really necessary to save this to table? A report can dynamically generate this sequence number with RunningSum property of textbox. No VBA needed.

    Essentially same topic as your earlier thread https://www.accessforums.net/access/...ter-55425.html
    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
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Code:
    I have also made a query that uses the Job_ID on that form and counts how many times that ID appears in the workdays table.

    As I said here June I have that part working. I said it in the thread you linked to and here. That's not the question.

    I already have the ability to get the number of days assigned to a job. That's in its own query..

    I don't know how to use that query on my form. I want to use that value to name days automatically.

    In the last part of my post there I describe what I want to do with that value after I get it on the form. I want to add 1 to the number and put the word days before it.

    I don't need to save the generated number anywhere..

    My query will use the Job_ID on that form and counts the associated days.. all I need is the query result to be put there.

    I'm assuming its the row source I need to change. So I can include that, and ill include the sql for the query.. I don't know if that's what I need to put together this is the purpose of the question.

    Row source of the sub form: (this does not have the job ID on its the main form that does. but its where I want the number)
    Code:
    SELECT [Workdays].[Day_ID], [Workdays].[Staff_ID], [Workdays].[Day_Title], [Workdays].[Scheduled_Start], [Workdays].[Additional_Information], [Workdays].[Consecutive_Days], [Workdays].[Job_ID], [SiteT].[Site_Name] FROM (SiteT INNER JOIN JobT ON [SiteT].[Site_ID] =[JobT].[Site_ID]) INNER JOIN Workdays ON [JobT].[Job_ID] =[Workdays].[Job_ID];

    Query:
    Code:
    SELECT Workdays.Job_ID, Count(Workdays.Day_ID) AS CountOfDay_ID
    FROM Workdays
    GROUP BY Workdays.Job_ID
    HAVING (((Workdays.Job_ID)=[Forms]![JobF]![JOBID]));

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Speaking as someone who knew nothing about databases a few months ago it can be very confusing for both the person asking the question and the person answering. Often people asking don't know what they are asking.. They don't know the names of things they need to or procedures. So how can they ask?

    But its a two way road, I attempt to be as clear as possible after the countless times I've been refused help because I didn't include relevant information (even though I say in most posts if you need more just ask). Your answer is nothing to do with the question. All you had to do was read the first line and you can see that I have a counter working. I also say this on the thread you link to.

    I appreciate any form of help, if there is some.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    I did read your post but apparently did not comprehend the true need. If you already have the sequencing accomplished and just need the aggregate count included, options:

    1. possibly use Count() function in form footer section

    2. build report using Sorting & Grouping features with aggregate calcs in group and report header/footer sections

    3. join the GROUP BY query to the other query by linking on the Job_ID fields - however, the dataset will likely be not editable so probably not what you want for a form

    4. DLookup()
    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.

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Okay, thanks anyway. Ill look into this further over the weekend

  7. #7
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks for your suggestions June. I have this working now.

    Count on the footer as you suggested with +1 to that value. Then the default value of my text box is.

    Code:
    ="Day " & [day_count]
    every new day is now named automatically.

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

Similar Threads

  1. Replies: 0
    Last Post: 06-03-2014, 05:15 AM
  2. Replies: 7
    Last Post: 06-10-2013, 12:40 PM
  3. Replies: 2
    Last Post: 01-30-2013, 07:34 PM
  4. Replies: 3
    Last Post: 01-15-2013, 01:58 PM
  5. Replies: 7
    Last Post: 05-02-2012, 08:04 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