Solved

Fill Combo box with value from button

Posted on 2011-09-12
6
370 Views
Last Modified: 2013-11-27
I have a main form that users click a button to launch a search form from the main form, the search form has a combobox that I want filed with a value (i.e. ITEMNMBR). I tried the code below but it throws an error "Microsoft office access can’t find the form frmSearch referred to in a macro expression or Visual Basic code"
 
Private Sub btnSearch_Click()
DoCmd.OpenForm "frmSearch", , , , , acDialog
[Forms]![frmSearch]![cboSearchField] = "ITEMNMBR"
End Sub

Open in new window

0
Comment
Question by:skull52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 36524401
First, try removing the acDialog - because the next line of code will not execute until frmSearch is closed.

Private Sub btnSearch_Click()
DoCmd.OpenForm "frmSearch", , , , , acDialog
[Forms]![frmSearch]![cboSearchField] = "ITEMNMBR"
End Sub

Instead, in frmSearch ... set the Modal and PopUp properties to Yes.

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36524406

Private Sub btnSearch_Click()
DoCmd.OpenForm "frmSearch", , , , , acDialog

End Sub

Open in new window


in the load event of frmSearch use this code

Private sub From_load()

me.[cboSearchField].value = "ITEMNMBR"
end sub

Open in new window



note * post the RowSource of the combo box



0
 
LVL 75
ID: 36524460

Might as well just set the Default Value of  cboSearchField to "ITEMNMBR", then all you need is this:


Private Sub btnSearch_Click()
     DoCmd.OpenForm "frmSearch", , , , , acDialog
End Sub

mx
0
 

Author Comment

by:skull52
ID: 36524496
Thanks MX that did it.

Cap, I can't do the on-load event for the search form as there will be other values entered, I am putting a search button next to each control that is searchable and placing that value into the combo box. but thanks anyway.
0
 

Author Comment

by:skull52
ID: 36524526
I selected the wrong solution I meant to select MX's first solution  
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Report formatting issue 5 72
Looking for advice on how to develop a project database 2 46
Menus 6 54
Conditionally trimming using VBA 8 32
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question