Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Not In List - Add Item with 2 data fields

Posted on 2008-06-24
2
Medium Priority
?
595 Views
Last Modified: 2013-11-28
My Order form has a combobox called cboOrderStatusID.  
The underlying table has 3 fields OrderStatusID, OrderStatus and OrderStatusType.

If the Order Status entered is not in the list, the attached code allows the user to add a new item.  However, I would also like them to enter the OrderStatusType (which can be "Completed", "Processing" or "Not Started" - ideally they should be able to select one of these without typing it in full - perhaps from a list box.

Normally, where other fields must be completed when a new item is added, I create a popup form to enter all the details.  However, in this case it seems a bit cumbersome.

Is there another way?


Private Sub cboOrderStatusID_NotInList(NewData As String, Response As Integer)
On Error GoTo err_OrderStatusID_NotInList
 
    Dim ctl As Control
    Dim strSQL As String
        
    ' Return Control object that points to combo box.
    Set ctl = Me!cboOrderStatusID
    ' Prompt user to verify they wish to add new value.
    If MsgBox(NewData & " is not in the Order Status list. Would you like to add it?", vbOKCancel) = vbOK Then
        ' Set Response argument to indicate that data is being added.
        Response = acDataErrAdded
        ' Add string in NewData argument to table.
        NewData = CapitalizeFirst(NewData)
        strSQL = " INSERT INTO tblOrderStatus ( OrderStatus ) SELECT '" & Proper(NewData) & "'"
        DoCmd.SetWarnings False
        DoCmd.RunSQL strSQL
        ctl.Value = NewData
        DoCmd.SetWarnings True
    Else
        ' If user chooses Cancel, suppress error message and undo changes.
        Response = acDataErrContinue
        ctl.Undo
    End If
        
exit_cboOrderStatusID_NotInList:
    Exit Sub
    
err_OrderStatusID_NotInList:
    If Err = 2113 Then
        Err = 0
        Resume Next
    Else
        MsgBox Str(Err)
        MsgBox Err.Description
        Resume exit_cboOrderStatusID_NotInList
    End If
End Sub

Open in new window

0
Comment
Question by:Ludique
[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 Comments
 
LVL 8

Accepted Solution

by:
Emil_Gray earned 2000 total points
ID: 21862667
Create a combo box and make it invisible on your form. When the criteria is met make it visible and give it the focus automatically. Have as its record source just the three items. That way if the user types a 'C' then 'Completed' is entered, an 'N' then 'Not Started' is entered or a 'P" then 'Processing' is entered since either would autocomplete. Have the code then make the combo box invisible again.
0
 

Author Comment

by:Ludique
ID: 21862726
Excellent.  Very neat.  Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

618 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