![]() |
|
|
|||||||
|
|
|
LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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")
|
|
#2
|
|||
|
|||
|
Can you post your project example?
|
|
#3
|
|||
|
|||
|
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?
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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
|
|
#7
|
|||
|
|||
|
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 |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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 |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |