Solved

Fill Combo box with value from button

Posted on 2011-09-12
6
330 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 119

Expert Comment

by:Rey Obrero
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now