Solved

Fill Combo box with value from button

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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