Results 1 to 4 of 4
  1. #1
    tslupphaug is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    2

    Open Form and add new record, but autofill some info based on current combobox selection

    Hello friendly internet!



    Click image for larger version. 

Name:	AddNewDocPrntscrn.png 
Views:	13 
Size:	7.4 KB 
ID:	22765

    I'm working with the following 3 forms (see screenshot above):
    1. fmnuNavH
    2. frmDocListByProject
    3. frmDocListByProject_SUB

    For simplicity within this thread, I'll simply call them "Nav", "Sort" and "Show".
    Well, the Nav form can be ignored completely I guess.

    My "Show" subform shows all documents based upon what project you choose from the Combobox in the "Sort" form. I want to make it easy for users to add more documents to that project, so I added a "Add New Document" button to my "Sort" form. OnClick I want to open my frmDocDetails (see below) and go to new entry.

    Click image for larger version. 

Name:	frmDocDetails.png 
Views:	15 
Size:	28.0 KB 
ID:	22767

    Opening up a new (entirely blank) new entry in the frmDocDetails is easy enough. But what I'm having problems with is having my fields "Project No", "Project Name" and "Client" (3 fields at the top there) being autofilled based upon my current view selected in my "Sort" form (and currently shown in my "Show" form for that matter).
    Don't know if it matters, but for info: "Project No" and "Project Name" comes from "tblProjects", while "Client" comes from "tblClients". They're obviously linked together in Relationships though.

    I'm pretty new to Access and macros etc.. So please go easy on me
    Best regards.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am having a hard time following. You have a new form open so that you can add a new record? Then you would want to open your form to open and show only a new record.

    It is confusing when you state that you want a data entry form and also display relative records.

    Perhaps you should work on creating a Main form with a subform and get your Master/Child Link fields set up correctly. Maybe use the wizard. Afterwards, you could create an unbound combo to "Filter" the Main form. The combo would really work independently from your main form. The combo would act as a way to get user input. It would not be bound and would not update data in your tables. You would simply use the value of the combo to apply a Filter to the form.

  3. #3
    tslupphaug is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    2
    Quote Originally Posted by ItsMe View Post
    I am having a hard time following. You have a new form open so that you can add a new record? Then you would want to open your form to open and show only a new record.

    It is confusing when you state that you want a data entry form and also display relative records.

    Perhaps you should work on creating a Main form with a subform and get your Master/Child Link fields set up correctly. Maybe use the wizard. Afterwards, you could create an unbound combo to "Filter" the Main form. The combo would really work independently from your main form. The combo would act as a way to get user input. It would not be bound and would not update data in your tables. You would simply use the value of the combo to apply a Filter to the form.
    I'll try to explain as good as I can.
    My subform is set up with master/child link fields (linked to project). But the subform actually gets its data from a query, not directly from a table. The query asks for only the latest revision of each document. If you take a look at my second screenshot ("Document Details" pop-up form), I've made it so that you may add several revisions for each document. My overview "Show" form is just showing the latest status of all documents. If you double click any of the documents on the list, you'll get this pop-up so that you'll have the full history shown for each document.

    The only thing I'd like to do is open the "Document Details" form, keep "Project No", "Project Name" and "Client" but have the rest emptied ready for a new document to be added (for the project that I'm currently viewing). I don't know if this helped any?


    Edit, additional info about how my database is set up and works: I see that I cut out a lot of details on my first screenshot. Tried to make it easier to understand, but I might just have caused more confusion:
    This is how my subform looks like when getting the data directly from my "last revision query" (qryDocsByLastRev):
    (NB! Note that this shows ALL documents in my database and each document's latest revision - not sorted by which project they belong to)
    Click image for larger version. 

Name:	frmDocList-last revisions-not sorted by project.png 
Views:	8 
Size:	43.6 KB 
ID:	22773

    And this is how it looks after I've sorted it by project using my combobox in my main form:
    Click image for larger version. 

Name:	frmDocList-last revisions-sorted by project.png 
Views:	7 
Size:	30.1 KB 
ID:	22774

    So if I from the previous overview e.g. double-click on the "Historical Data" document, this is what I open up: "Document Details" form, with the basic doc.info at the top and a revision sub-form:
    Click image for larger version. 

Name:	docdetailsform.png 
Views:	8 
Size:	75.0 KB 
ID:	22775

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    But the subform actually gets its data from a query
    I am still not understanding, perfectly. However, there are only a couple ways you can affect which records are viewed in a form. One way, you can use the .Filter property of the form. To do this, all you need is WHERE criteria.
    "[ThisField] = " & MyVariable

    Another way is to edit the Recordsource of the form and limit the number of records retrieved. You can create your standard SELECT statement that would apply to any scenario when the form is open and also a dynamic WHERE clause. You would combine the two strings, the generic SELECT statement and the WHERE statement, and apply this directly to the Form's RecordSource or to the SQL of a Query Object.

    In order to edit the SQL of an existing Query Object, you would use DAO and QueryDefs to access a QueryDef's SQL property.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2014, 01:20 PM
  2. AutoFill Based on ComboBox Selection
    By chelseagardens in forum Forms
    Replies: 3
    Last Post: 08-08-2013, 01:14 PM
  3. Replies: 2
    Last Post: 04-02-2013, 02:24 AM
  4. Replies: 1
    Last Post: 05-31-2012, 01:01 PM
  5. Replies: 0
    Last Post: 08-24-2010, 06:38 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