Kamis, 04 Mei 2017

Re: [MS_AccessPros] Update another field from NotInList event

 

John,


I have no hesitation to admit that this code you told me is totally new for me and i have never used it or seen it before, therefore i'm still not following what you are telling me to do.

1) In form "frmAddressSubform" Combo Box "cboResidenceCity" its Control Source is "MainCityName" and Row Source is:
SELECT DISTINCT MainCity.MainCityName, MainCity.Country
FROM MainCity
ORDER BY MainCity.MainCityName;
Bound Column =1
Column Count=2

Which now shows "MainCityName" and "Country" in two columns.

On Not in List event i have removed the previous code, and now it is:
Private Sub cboResidenceCity_NotInList(NewData As String, Response As Integer)
    DoCmd.OpenForm "AddCityCountry", , , , , acDialog
End Sub

Is it right ?

Now if the "MainCityName" is not in the drop down list, would the user type only new city name or both city name and country like Test,Test1 ?
When i tried this i got error message "Invalid use of Null" and on clicking Debug button it shows highlighted the line:
    intI = InStr(Me.OpenArgs, ",")
closing the code window, it opens Form "AddCityCountry" on first record, on entering new record as Test and Test1, the command button to save the record click event does not works

Private Sub CmdSaveRcrdAddCityCountry_Click()
    Dim msg As String
    msg = msg & "Do you want to Save this record?"
    If MsgBox(msg, vbYesNo, "SAC Pakistan Guide - Confirmation!") = vbYes Then
        DoCmd.Save
    Else
        Me.Undo
    End If
End Sub

On clicking Close button, the form closes and immediately error message displays "The text you entered isn't an item in the list. 

Also in the code you gave me for form "AddCityCountry" should i change them as follows marked with <====

Private Sub Form_Load()
Dim intI As Integer, strCity As String, strCountry As String

    ' If nothing in OpenArgs,
    If Len(Me.OpenArgs) = 0 Then
        ' Nothing to do
        Exit Sub
    End If

    ' See if there's a comma
    intI = InStr(Me.OpenArgs, ",")
    ' If no comma,
    If intI = 0 Then
       ' Just set City
       Me.MainCityName = Me.OpenArgs    ' <=========
    Else
        ' Set City and Country
        Me.MainCityName = Left(Me.OpenArgs, intI - 1) ' <========
        Me.Country = Trim(Mid(Me.OpenArgs, intI + 1))
    End If
End Sub

I am totally confused. But also sure that you will put me on the right track and guide as you always did for me before, while i am learning something new for me from you.
Thanks in advance for help.
Khalid
 
 


 


---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

It's for the AddCityCountry form.  The code extracts City and Country from the OpenArgs you pass from frmAddressSubform.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On May 4, 2017, at 9:55 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



John,

Sorry for my little knowledge is this event for Form "AddCityCountry" or Form "frmAddressSubform" ?

Khalid
 


---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Khalid-

Private Sub Form_Load()
Dim intI As Integer, strCity As String, strCountry As String

    ' If nothing in OpenArgs,
    If Len(Me.OpenArgs) = 0 Then
        ' Nothing to do
        Exit Sub
    End If

    ' See if there's a comma
    intI = Instr(Me.Openargs, ",")
    ' If no comma,
    If intI = 0 Then
       ' Just set City
       Me.City = Me.OpenArgs
    Else
        ' Set City and Country
        Me.City = Left(Me.OpenArgs, intI - 1)
        Me.Country = Trim(Mid(Me.OpenArgs, intI + 1))
    End If
End Sub


John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On May 4, 2017, at 9:12 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



John,

I have made a new Form "AddCityCountry" having Record Source table "MainCity". Also added field
"Country" in table "MainCity" for the current data in table "MainCity" against field "MainCityName" entered manually country names.

The portion you told:
You can pass what the user entered in the Openargs parameter. 
In the Load event of the data entry form, parse the two parts (look for the comma with InStr)
and place the values in the two controls.

I could not get it John, could you please explain or give example.

I have done this portion:
You'll also need code after the form closes (probably
via a Save and Close button on the dialog form) to check to see that the data got entered.

Regards,
Khalid

 


---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Khalid-

If you put both fields in one table, you need one combo box that displays both fields (city, country), and instead of simply inserting the data, you need to open a form in data entry and dialog mode (to halt the calling code) that lets the user enter both fields.  You can pass what the user entered in the Openargs parameter.  In the Load event of the data entry form, parse the two parts (look for the comma with InStr) and place the values in the two controls.  You'll also need code after the form closes (probably via a Save and Close button on the dialog form) to check to see that the data got entered.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On May 4, 2017, at 11:01 AM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



Hi John,


I have a Form "frmAddressSubform".


It has one Control "cboResidenceCity" , on its NotInList event following is the code:


    'On Error GoTo cboResidenceCity_NotInList_Err

    Dim intAnswer As Integer

    Dim strSQL As String

    intAnswer = MsgBox("City Name '" & Chr(34) & NewData & _

        Chr(34) & "' is not currently listed." & vbCrLf & _

        "Would you like to add it to the list now?" _

        , vbQuestion + vbYesNo + vbDefaultButton2, "SAC Pakistan - Guide")

    If intAnswer = vbYes Then

         strSQL = "INSERT INTO MainCity ([MainCityName])" & _

                 "VALUES ('" & NewData & "');"

        DoCmd.SetWarnings False

        DoCmd.RunSQL strSQL

        DoCmd.SetWarnings True

        MsgBox "The new 'City Name' " & Chr(34) & NewData & Chr(34) & " has been added to the list." _

            , vbInformation, "SAC Pakistan - Guide"

        Response = acDataErrAdded

    Else

        MsgBox "Please choose a 'City Name' from the list." _

            , vbInformation, "SAC Pakistan - Guide"

        Response = acDataErrContinue

    End If

cboResidenceCity_NotInList_Exit:

    Exit Sub

'------------------

Next control is "cboCountry" with similar NotInList event.


I am thinking to add a field "Country" in tbl "MainCity" and get its value as

=[cboResidenceCity].Column(1) and make control as text field instead of combobox.


My main question is if i do so, when "cboResidenceCity" NotInList event triggers how 

will the field "Country" be filled when it is a new "MainCity" ?


Please help.

Regards,


Khalid












__._,_.___

Posted by: khalidtanweerburrah@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (7)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar