Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-21-2009, 12:07 PM
jhjarvie jhjarvie is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Sep 2008
Posts: 12
jhjarvie is on a distinguished road
Default Select Item from drop down list rather than enter in an input box????

I have a simple bit of code which I use to force various entrys in specific fields after a trigger event...
I would like to use a drop down list of set values other than an input box which doesnt offer the user any choice (See last line of the code below)......any ideas??

If Me.Transaction_Type = "Repair" Then
Me.Part_No = "TOOL-REPAIR"
Me.Supplier = "00000"
Me.Stock_Status = "N/A"
Me.Qty_Req = "1"
Me.Work_Description = InputBox("Enter description of the Tool Repair")
Me.Work_Supplier = InputBox("Enter Supplier Code")

Reply With Quote
  #2  
Old 09-21-2009, 05:19 PM
Yance Yance is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Aug 2009
Posts: 13
Yance is on a distinguished road
Smile

Can you post your project example?
Reply With Quote
  #3  
Old 09-22-2009, 12:53 PM
jhjarvie jhjarvie is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Sep 2008
Posts: 12
jhjarvie is on a distinguished road
Default Input Box / Dropdown list Issues

Maybe the issue is easier put this way.....

Is it possible to make an input box (using VBA) a pop-up combo box instead?

i.e: I am using the following code....

me.AnswerField = InputBox("Select from the following selection (i.e. Mandatory, GMP/SHE)", "Phase 1 Employee Induction")

However I'd like the users to select the input from a combo box (dropdown list) instead of an input box?

Is this possible?
Reply With Quote
  #4  
Old 09-22-2009, 02:48 PM
CGM3 CGM3 is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Sep 2009
Location: Atlanta, GA
Posts: 36
CGM3 is on a distinguished road
Default

You'll have to build your own "input box" by creating a new form, with the list of responses in a dropdown combo box, that is called from the "main" form. Here's a snippet of sample code I have in my available notes:

-------------------------------------------------------------------

Code for a “pop up” form:

Invoking “pop up” frmPopUpBox from “master” frmMain:

Dim cA As String
Dim stDocName As String
Dim stLinkCriteria As String

Me.Tag = “text” ‘ this text is to be accessed by the “pop up”
stDocName = "frmPopUpBox"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog

Accessing “master” from “pop up”:

Dim cA As String
cA = Form_frmMain.Tag ‘ retrieves “text”
cA = Form_frmMain!txtText.Value ‘ retrieves value of text field txtText on “master”
Me.Tag = "more text" ‘ this text is to be accessed by the “master”
DoCmd.Close ‘ closes “pop up”

Accessing “pop up” from “master” after “pop up” closes

cA = Form_frmPopUpBox.Tag ‘ retrieves “more text”

--------------------------------------------------------------------

I can consult my project that uses this tomorrow, at work, for further info.
Reply With Quote
  #5  
Old 09-23-2009, 04:11 AM
CGM3 CGM3 is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Sep 2009
Location: Atlanta, GA
Posts: 36
CGM3 is on a distinguished road
Default

Create a new form, with no record source, and give it a dropdown combo box (with a record source equal to a table or query that lists the acceptable values), a command button, and a label that tells the user to select the desired Supplier Code from the combo box.

I used frmPopUpBox, cboPopUpList, cmdClose, and lblPopUp as the names for the form, combo box, command button, and label. Give the command button this code:

Private Sub cmdClose_Click()
'
' if no errors, close pop-up form
'
On Error GoTo Err_cmdClose_Click

If Trim(cboPopUpList.Value) = "" Then
MsgBox "You must indicate a Supplier Code from the list!", vbOKOnly + vbCritical, "Missing Supplier Code"
Exit Sub
End If
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub

Then your "home form" code becomes:

' add these variable definitions in the routine
Dim stDocName As String, stLinkCriteria As String

If Me.Transaction_Type = "Repair" Then
Me.Part_No = "TOOL-REPAIR"
Me.Supplier = "00000"
Me.Stock_Status = "N/A"
Me.Qty_Req = "1"
Me.Work_Description = InputBox("Enter description of the Tool Repair")
stDocName = "frmPopUpBox"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Me.Work_Supplier = Form_frmPopUpBox!cboPopUpList.Value

That should do what you want.
Reply With Quote
  #6  
Old 09-23-2009, 04:31 AM
dcrake's Avatar
dcrake dcrake is offline Windows XP Access 2003 (version 11.0)
Expert
 
Join Date: Aug 2009
Posts: 438
Blog Entries: 1
dcrake is on a distinguished road
Default

Could be an issue with the last line of code

Me.Work_Supplier = Form_frmPopUpBox!cboPopUpList.Value


If the form is not loaded it will generate an error. Therefore it should be the popup form that is populating the main form control. such as:

Code:
 
Sub frmPopUpBox_Unload()
 
If Me.CboPopUpList <> "" Then
    Forms("MainFormName")("ControlName") = Me.CboPopUpList
End If
 
DoCmd.Close
 
End Sub
David
Reply With Quote
  #7  
Old 09-23-2009, 01:04 PM
jhjarvie jhjarvie is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Sep 2008
Posts: 12
jhjarvie is on a distinguished road
Default

Works Great........However if the user chooses nothing from the drop down list and leaves the feild null, no error or error message is returned

Private Sub btn_Close_Click()
'
' if no errors, close pop-up form
'
On Error GoTo Err_btn_Close_Click
If Trim(supplierCode.Value) = "" Then
MsgBox "You must choose a Supplier Code from the list!", vbOKOnly + vbCritical, "Missing Supplier Code"

Exit Sub
End If
DoCmd.Close
Exit_btn_Close_Click:
Exit Sub
Err_btn_Close_Click:
MsgBox Err.Description
Resume Exit_btn_Close_Click
End Sub

Any help
Reply With Quote
  #8  
Old 09-23-2009, 02:20 PM
CGM3 CGM3 is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Sep 2009
Location: Atlanta, GA
Posts: 36
CGM3 is on a distinguished road
Default

Have you tried--

If IsNull(supplierCode.Value) Then
MsgBox "You must choose a Supplier Code from the list!", vbOKOnly + vbCritical, "Missing Supplier Code"

ElseIf Trim(supplierCode.Value) = "" Then

Alternatively, you could try initializing the value of supplierCode as a zero-length string ("") when the "pop up" form is called.
Reply With Quote
  #9  
Old 09-24-2009, 12:56 PM
jhjarvie jhjarvie is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Sep 2008
Posts: 12
jhjarvie is on a distinguished road
Default

Yeh, Got it with this code... Thanks

On Error GoTo Err_btn_Close_Click
If IsNull(Raised_By.Value) Then
MsgBox "You must choose a Name from the list!", vbOKOnly + vbCritical, "Missing Name"
Exit Sub
End If
DoCmd.Close
Exit_btn_Close_Click:
Exit Sub
Err_btn_Close_Click:
MsgBox Err.Description
Resume Exit_btn_Close_Click
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
add item to a list box rowsource(table/query) dollygg Access 0 08-26-2009 09:51 AM
drop down list tceicher Access 5 08-13-2009 03:41 AM
Combo-box to select item to edit in Form DHavokD Forms 7 06-05-2009 11:39 AM
Open Form with a drop down list box Rinehart Forms 0 08-10-2008 06:53 PM
I can't create a drop-down list box cpuser Access 4 02-18-2008 07:11 AM


All times are GMT -8. The time now is 08:22 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.