Results 1 to 3 of 3
  1. #1
    empyrean90 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    5

    Query, Form, Code help

    I am creating a project database and to help reduce the potential for user input errors I want any forms opened off the main form to display the record(s) that match the project currently pulled up and if there is no records to put the project number in the appropriate field on the new form that is opened.

    One instance of this is to display the costs for a project. I have a button on the main form that will open the form that displays the results from the query that gathers and calculates the total. I have the following code for the button:

    Private Sub Command131_Click()
    DoCmd.OpenForm "CalculatedCost"
    Forms!CalculatedCost.ProjectID = Me.ProjectID
    End Sub

    The parameter for the query is set to get the value placed in the ProjectID field on the CalculatedCost form. It works great when I am opening a record that has costs already associated with it but when there is no cost data associated with the open project the form opens as a blank form.

    Is there a way to have it display the value that was entered as the parameter into the ProjectID field on the cost form if the query returns no results?

    Any help on this would be greatly appreciated.

    Ryan

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Have you considered a form/subform arrangement?

    Otherwise, the code would have to create a record for the form to open to or have code that will cancel the form open if no data exists.
    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
    empyrean90 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    5
    I did think of that but the problem is I would have 17 subforms on the page which would get really confusing. Also, not every project needs to have a record in each of the subforms and even with the subforms they do not carry the value in the related field over from the main to the subform.

    I was able to find a way to do this by using a query, coded button, an expression and some manipulation of the tab order but it seems to me like there is a better route to use than that

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

Similar Threads

  1. Replies: 3
    Last Post: 07-20-2012, 11:41 AM
  2. query using code
    By rohini in forum Queries
    Replies: 1
    Last Post: 05-17-2012, 03:46 AM
  3. Code to create a query from a form
    By stryder09 in forum Queries
    Replies: 15
    Last Post: 10-17-2011, 01:55 PM
  4. VBA code to display value from SQL query
    By agent- in forum Programming
    Replies: 9
    Last Post: 05-05-2011, 03:52 PM
  5. Replies: 6
    Last Post: 11-05-2010, 10:11 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