?
Solved

Fill Combo box with value from button

Posted on 2011-09-12
6
Medium Priority
?
373 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

743 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