Results 1 to 3 of 3
  1. #1
    Xine is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    19

    Post Add new record function of my city combo box not working

    Working: citycombo "AfterUpdate" auto populates the Area, Community and Province fieilds
    Working: citycombo "Not on list" event allows you to update tbl CityArea
    Not Working: "Not on List" is to apply the new City, Area, Community and Province to the form ----instead I get "Please try again" message (re: If IsNull(result))

    Can anyone see the error in the code below?

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

    Private Sub citycombo_AfterUpdate()

    Me.Area = Me.citycombo.Column(2)
    Me.Community = Me.citycombo.Column(3)
    Me.OrgProv = Me.citycombo.Column(4)

    If Me.citycombo = "" Then
    Me.Area = ""
    Me.Community = ""
    Me.OrgProv = ""
    End If



    End Sub

    Private Sub citycombo_NotInList(NewData As String, Response As Integer)

    Dim Result
    Dim Msg As String
    Dim CR As String

    CR = Chr$(13) ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub

    ' Ask the user if he or she wishes to add the new city.
    Msg = "'" & NewData & "' is not in the list of cities." & CR & CR
    Msg = Msg & "Do you want to add it?"
    If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
    ' If the user chose Yes, start the CityArea form in data entry
    ' mode as a dialog form, passing the city name in
    ' NewData to the OpenForm method's OpenArgs argument. The
    ' OpenArgs argument is used in CityArea form's Form_Load event
    ' procedure.
    DoCmd.OpenForm "frmCityArea", , , , acAdd, acDialog, NewData
    End If

    ' Look for the city the user created in the Org_Don form.
    Result = DLookup("[City]", "tbl CityArea", _
    "[OrgCity]='" & NewData & "'")

    If IsNull(Result) Then
    ' If the city was not created, set the Response argument
    ' to suppress an error message and undo changes.
    Response = acDataErrContinue
    ' Display a customized message.
    MsgBox "Please try again!"
    Else
    ' If the customer was created, set the Response argument to
    ' indicate that new data is being added.
    Response = acDataErrAdded
    End If

    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    in the ON EXIT property of the form frmCityArea issue REFRESH (this may not be needed on some versions of access and whether or not you're using bound forms) command and requery the combo box on the original form (i.e. forms!frm_main!comboName.requery)

  3. #3
    Xine is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    19
    I changed a field name (in orange below) and it's ALMOST working.
    Now, the "Not In List" event triggers, I select "yes" from the message box and enter new data into the linked form (frmCityArea), BUT then "Not in List" message box pops up again and when I choose "no", that's when the new info I've entered populates my form.

    Any suggestions as to why this is happening?


    Private Sub citycombo_AfterUpdate()

    Me.Area = Me.citycombo.Column(2)
    Me.Community = Me.citycombo.Column(3)
    Me.OrgProv = Me.citycombo.Column(4)

    If Me.citycombo = "" Then
    Me.Area = ""
    Me.Community = ""
    Me.OrgProv = ""
    End If
    End Sub


    Private Sub citycombo_NotInList(NewData As String, Response As Integer)

    Dim Result
    Dim Msg As String
    Dim CR As String

    CR = Chr$(13) ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub

    ' Ask the user if he or she wishes to add the new city.
    Msg = "'" & NewData & "' is not in the list of cities." & CR & CR
    Msg = Msg & "Do you want to add it?"

    If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then

    ' If the user chose Yes, start the CityArea form in data entry
    ' mode as a dialog form, passing the city name in
    ' NewData to the OpenForm method's OpenArgs argument. The
    ' OpenArgs argument is used in CityArea form's Form_Load event
    ' procedure.

    DoCmd.OpenForm "frmCityArea", , , , acAdd, acDialog, NewData
    End If

    ' Look for the city the user created in the form.
    Result = DLookup("[City]", "tbl CityArea", _
    "[City]='" & NewData & "'")

    If IsNull(Result) Then
    ' If the city was not created, set the Response argument
    ' to suppress an error message and undo changes.
    Response = acDataErrContinue
    ' Display a customized message.
    MsgBox "Please try again!"
    Else
    ' If the customer was created, set the Response argument to
    ' indicate that new data is being added.
    Response = acDataErrAdded
    End If

    End Sub

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

Similar Threads

  1. Replies: 7
    Last Post: 09-04-2015, 11:55 AM
  2. Replies: 4
    Last Post: 01-25-2015, 01:20 PM
  3. Replies: 11
    Last Post: 06-05-2013, 08:15 AM
  4. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  5. DLookup Function for City/Region/Country?
    By cap.zadi in forum Forms
    Replies: 6
    Last Post: 11-22-2012, 11:16 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