Results 1 to 7 of 7
  1. #1
    Mike79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    18

    How to set Do.Cmd.OpenForm and then set a combobox value

    Hi,

    I'm pretty new to access, so this may be quite easy but I just can't get it. Situation as follows.

    I have a split form for Inventory (InventoryF) that has a combo box that allows me to select a Trailer number, then the contents of the trailer are displayed.
    I have a second form for Trailer/Vehicle information (VehicleF) that shows license numbers, etc.


    I would like to use an event procedure on a double click event (or if there is a better suggestion than double click, I am all ears), in the VehicleF that will open the InventoryF and set the combobox to whatever I double clicked on. (i.e. double click on Trailer 1 in the VehicleF, and it opens InventoryF to Trailer1).

    Just opening the form is real basic (DoCmd.OpenForm "InventoryF"). But setting the combo box, I've failed. I tried:

    DoCmd.OpenForm "InventoryF", _
    WhereCondition:="cboTrailer=" & Me.TrailerName

    (cboTrailer is my combo box on InventoryF, and TrailerName is the corresponding name on VehicleF)

    That returns a Syntax Error (3075) saying I have a missing operator. I tried a slew of other things too. Any help is appreciated. Thank you!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the value is text it needs delimiters:

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Mike79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    18
    Thanks Paul. I went in that direction on one of my tries.

    DoCmd.OpenForm "InventoryF", , , "cboTrailer = '" & Me.TrailerName & "'"

    With this, it errors wanting a value for cboTrailer. I'm concerned I'm coming at this from the wrong angle completely, but I'm learning slowly....

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You can't set the value of an combo in that fashion, you would have to pass the value to the form, and process it that way in the forms load event.

    However If you want to filter the form by that value then use the field name to do it;

    Code:
    DoCmd.OpenForm "InventoryF", , , "[YourTailerFieldName] = '" & Me.TrailerName & "'"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll get out of the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Mike79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    18
    Thanks Paul that worked! You've been very helpful. A couple more questions though if you dont mind.

    1. The users can open the InventoryF in a secondary way, so I previously had a default setting for FormLoad so that it opened to a Select Trailer generic screen. If I have a default in formload, the code you suggested doesn't work because it takes that default. Is there a work around?
    2. Is it possible to also set the combo box? The reason being, is that the users can use secondary boxes for search functions. Those search boxes look to see what trailer is selected in the combo box. If the combobox is null, it doesn't search correctly.

    Thanks again.

  7. #7
    Mike79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    18
    Oh shoot, I just realized there are 2 of you responding. Sorry, newb on this forum too. Minty, my last post should have been addressed to you.

    Paul, you definitely aren't in the way! If there is a smarter way I'm all ears.

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

Similar Threads

  1. How to update a combobox with openForm?
    By Nightcrawler in forum Access
    Replies: 8
    Last Post: 02-20-2018, 08:30 AM
  2. Do.Cmd.OpenForm with Where clause
    By moneypennie21 in forum Access
    Replies: 5
    Last Post: 05-24-2017, 05:08 AM
  3. OpenForm to specific tab
    By rivereridanus in forum Access
    Replies: 1
    Last Post: 06-28-2012, 07:32 PM
  4. Getting to a tab on openform
    By Swarland in forum Programming
    Replies: 5
    Last Post: 12-12-2010, 11:22 AM
  5. OpenForm macro
    By tguckien in forum Forms
    Replies: 3
    Last Post: 07-06-2010, 09:12 AM

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