Results 1 to 10 of 10
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Passing Values

    Hello all

    I'm creating a database, but doing it a slightly different way than I have done in the past and I have encountered an issue I've not had before.

    I have a main Menu, the main Menu button to Add new Employee Opens the Very First Form to add a new employee

    The First Screen is where the company selects a company name from the list, and then moves to the next page to select a subsequent department. Sounds easy.

    The relationships are:
    tblCompanyName -
    PK = CompanyNameID
    Txt - CompanyName - unbound combobox on the form

    The person updating clicks on the next button after selecting the companyname from the combo box CompanyName

    Code:
    DoCmd.OpenForm "frmAddNewEmployeeDepartment",,,[CompanyNameId] = " & Me![CompanyName],,,Me!CompanyName
    Then on Open.

    Code:
    If Me.OpenArgs <> "" then
    If Me![CompanyNameID].DefaultValue = "" Me.OpenArgs & ""
    End If
    The follow on page is the department in the company.
    tblCompanyDepartment -
    PK = CompanyDepartment
    FK - CompanyNameID
    Txt - CompanyDepartment

    The follow on from this is the employee. I All my subsequent forms open fine and pass the openargs to the relevant tables and relationships all work, its just the very first step I'm stuck with.

    When I am in the tblCompanyName - even though the PK is linked to the FK 1 to many, for tblCompanyDepartment, there is no value in tblCompanyName



    Can someone suggest a solution as my queries will not pull down reports as the first table is blank.

    Regards

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,413
    struggling to follow your description - what is 'first screen' and 'next page'

    But from what you are describing can be achieved with what are referred to as cascading combos. All on one form

  3. #3
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Hi Cj

    First screen - is actually my first form.

    Next Page - is the new form a user moves to.

    I understand cascading combos, one of my previous databases does have several of them, but the user wishes to have one form (page) per selection. Form, 1, Select Company, Form 2, Select Department, Form 3, Enter Employee, Form 4, Select Job Title, and so on.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,413
    this line in your open events seems to have a extra if

    If Me![CompanyNameID].DefaultValue = "" Me.OpenArgs & ""


    but that would have generated an error on compilation

  5. #5
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    I'm not sure where that came from I did a copy and paste and the second if is not in the code I have - that is not the issue.

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    What is the row source of the unbound combo on the first form? Does it have two columns (CompanyID and CompanyName) with the first column hidden and set as the bound column?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    The row source of the unbound combo on the first form is tblCompanyName (the first column is hidden and the set as the bound column. As you would expect.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,413
    I'm not sure where that came from I did a copy and paste and the second if is not in the code I have - that is not the issue.
    perhaps there is something wrong with your copy/paste since

    Me![CompanyNameID].DefaultValue = "" Me.OpenArgs & ""

    is not valid syntax and would be highlighted red as such

    if the companynameID field is a string then valid code would be

    Me![CompanyNameID].DefaultValue = "'" & Me.OpenArgs & "'"
    or
    Me![CompanyNameID].DefaultValue = """ & Me.OpenArgs & """""

    and if a number

    Me![CompanyNameID].DefaultValue = Me.OpenArgs

  9. #9
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    is not valid syntax and would be highlighted red as such
    Do you have Option Explicit declared in All of your code modules?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #10
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Steve,
    Have you made any changes to the code you showed in the original post? Can you please post what you have now (in both procedures) and what the exact problem is?
    I don't think you want to set the DefaultValue property as that would apply for new entries only, I believe you want to actually populate the control with the passed value:
    Code:
    Me.CompanyNameID = Me.OpenArgs
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Passing values to report giving between values
    By Budatlitho in forum Reports
    Replies: 3
    Last Post: 03-09-2022, 04:01 PM
  2. Passing Values from one form to another
    By fret hack in forum Forms
    Replies: 3
    Last Post: 11-19-2017, 11:01 AM
  3. Passing values vs. objects
    By Monterey_Manzer in forum Programming
    Replies: 1
    Last Post: 09-26-2014, 12:31 PM
  4. Passing values to another form
    By jlt199 in forum Forms
    Replies: 11
    Last Post: 02-25-2014, 04:50 PM
  5. Passing Values
    By dromorkid in forum Forms
    Replies: 0
    Last Post: 11-25-2008, 05:04 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