Results 1 to 5 of 5
  1. #1
    mattvogt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Location
    Denver Co
    Posts
    5

    Form not sourcing new data: cbo Limit to list, add, open form (to fill in new data)

    I'm trying to make my form more user friendly, and when a value isn't in the db I want to a form to open and so the right data can be entered. I have the form
    I have the "Limit to list" property set, the vb yes/no box appears, the data is added, and my form opens (the macro on the last line). The issue I have is that my newly entered data isn't what appears in the form, and so when I go to save rest of the new data, I have redundant primary keys as the "Arbor Number" was already added.

    Ideally, I would like to keep this code and just have the form open with the new arbor number already pulled up and ready for customer information to be entered into the other fields of the form.

    [code]Private Sub cboArborNumber_NotInList(NewData As String, Response As Integer)

    Dim strSQL As String
    Dim i As Integer
    Dim Msg As String

    'Exit this sub if the combo box is cleared
    If NewData = "" Then Exit Sub

    Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
    Msg = Msg & "Do you want to add it?"

    i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Arbor Number...")
    If i = vbYes Then
    strSQL = "Insert Into tblCustomers ([ArborNumber]) " & _
    "values ('" & NewData & "');"
    CurrentDb.Execute strSQL, dbFailOnError
    Response = acDataErrAdded


    Else
    Response = acDataErrContinue
    End If
    DoCmd.RunMacro ("mcr")[Code]

    Thanks,

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    After adding the new data to tblCustomers, you have to requery the combo box to see the new entry.

    cboArborNumber.Requery should work.

    John

  3. #3
    mattvogt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Location
    Denver Co
    Posts
    5
    Thank you for your reply, however after the add I am opening a data entry form to enter the rest of the customer information. I want the ArborNumber to auto-populate into the field in the new form. What code would I use to do such a task?

    Thanks,

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Options:

    1. set the customer form DefaultValue property of ArborNumber textbox to reference the ArborNumber field on the first form

    2. VBA code in form Current event to populate the ArborNumber field
    Code can reference the ArborNumber field on first form
    or pass the ArborNumber in OpenArgs argument of OpenForm then reference OpenArgs to extract the value
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    mattvogt is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Location
    Denver Co
    Posts
    5
    Incredibly helpful, thanks! I set the default value to the ArborNumber and it is perfect.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-28-2013, 01:54 PM
  2. Replies: 2
    Last Post: 12-18-2012, 11:41 AM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Replies: 1
    Last Post: 12-21-2011, 02:11 PM
  5. Replies: 1
    Last Post: 11-13-2011, 08:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums