Solved

Fill Combo box with value from button

Posted on 2011-09-12
6
353 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
  • 2
  • 2
6 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

832 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