Not In list problem !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • luanhoxung

    #1

    Not In list problem !

    hi all !
    On my form, i have a combo box with using NotInList even.
    My combo box name Port. It is got from Table Port which have 2 fields:
    Port & Country
    i can add new Port from my combo box, but my goal is add new Port with
    Country. i tried more and more but not succeed.

    Pls give me a hand or any example code are appreciated.
    Thanks for ur time.

    here my code:

    Private Sub PORT_NotInList( NewData As String, Response As Integer)
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strMsg As String

    strMsg = "'" & NewData & "' hasnot in OurPort" & vbCrLf & vbCrLf
    strMsg = strMsg & vbCrLf & vbCrLf & "Do u want to add it?"
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
    Response = acDataErrContin ue
    Else
    Set db = CurrentDb
    Set rs = db.OpenRecordse t("TPORT", dbOpenDynaset)
    On Error Resume Next
    rs.AddNew
    rs!Port = NewData
    rs.Update
    If Err Then
    MsgBox "An error occured. Please try again."
    Response = acDataErrAdded
    End If
    End If
    rs.Close
    Set rs = Nothing
    Set db = Nothing

    End Sub


  • Tom van Stiphout

    #2
    Re: Not In list problem !

    On Wed, 20 Dec 2006 03:17:39 -0500, "luanhoxung "
    <luanhoxung@yah oo.comwrote:

    The best way is to pop up a form to ask for both fields. Open that
    form with acDialog in the DoCmd.OpenForm call so it becomes a modal
    dialog.

    The poor man's version would be to use an Input Box:
    rs.AddNew
    rs!Port = NewData
    rs!Country = InputBox("What country is this port in?")
    rs.Update

    -Tom.

    >hi all !
    >On my form, i have a combo box with using NotInList even.
    >My combo box name Port. It is got from Table Port which have 2 fields:
    >Port & Country
    >i can add new Port from my combo box, but my goal is add new Port with
    >Country. i tried more and more but not succeed.
    >
    >Pls give me a hand or any example code are appreciated.
    >Thanks for ur time.
    >
    >here my code:
    >
    >Private Sub PORT_NotInList( NewData As String, Response As Integer)
    >Dim db As DAO.Database
    >Dim rs As DAO.Recordset
    >Dim strMsg As String
    >
    >strMsg = "'" & NewData & "' hasnot in OurPort" & vbCrLf & vbCrLf
    >strMsg = strMsg & vbCrLf & vbCrLf & "Do u want to add it?"
    >If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
    >Response = acDataErrContin ue
    >Else
    >Set db = CurrentDb
    >Set rs = db.OpenRecordse t("TPORT", dbOpenDynaset)
    >On Error Resume Next
    >rs.AddNew
    >rs!Port = NewData
    >rs.Update
    >If Err Then
    >MsgBox "An error occured. Please try again."
    >Response = acDataErrAdded
    >End If
    >End If
    >rs.Close
    >Set rs = Nothing
    >Set db = Nothing
    >
    >End Sub
    >

    Comment

    • luanhoxung

      #3
      Re: Not In list problem !

      thanks alot, Tom !
      I will try doing ur advise.

      thanks again.

      Comment

      Working...