John,
OK got it all.
Thanks a lot,
Regards,
Khalid
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
John,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
That's why need to have a BeforeUpdate event in the form AddCityCountry to check to see if there's a valid value in Country. If not, set Cancel = True and tell the user the value must be supplied. If you have a list in a table of valid country names, you can use that to check that the value is correct. You can at least make sure they haven't left the field blank.
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 7, 2017, at 7:23 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
John,
If the user doesn't enters Country name and saves it without Country name, then what to do, so that blank Country name be filled.
whether to open form "AddCityCountry" separately to edit missing Country name or something else.
Regards,
Khalid
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
John,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Suggestion for what? I told you ways to validate the Country name.
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 7, 2017, at 6:19 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
John,
Question - 1 still needs your suggestion.
Regards,
Khalid
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
John,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
In the form you open as a dialog, you should give them bound fields to enter both City and Country. Consider creating a "lookup" table that contains a list of all the valid countries you service. Use that to validate the Country name or perhaps use a combo box for Country on the AddCityCountry form.
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 7, 2017, at 5:11 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
John,
Done as you told, fine it is working now.
As the code and forms are working now, some questions are coming to my mind.
1- What if user does not enters Country, should i make a separate form like "EditCityCountry"
OR we can manage it here in some code?
2- Nice approach you wrote:
You should also have code in Before Update to ensure they've entered a valid Country name in addition to the city name.
Question is what is the check or criteria to ensure they've entered a valid Country name?
Regards,
Khalid
,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
John,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
You're pointing to the Response line, but I assume you mean the MsgBox line above. You will see that error only if the user closes form AddCityCountry without saving the new record. You should have Save and Cancel buttons on that form. Save will simply save the record and close the form. Cancel will do a Me.Undo and close. You should also have code in Before Update to ensure they've entered a valid Country name in addition to the city name.
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 7, 2017, at 3:44 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
John,
OK got it.
See below my question in comment below:
Private Sub cboResidenceCity_NotInList(NewData As String, Response As Integer)
Dim strName As String, strWhere As String
gstrAppTitle = "SAC Pakistan Guide"
' User typed in a City Name that's not in the list
strName = NewData
' Build the verification search string
strWhere = "[MainCityName] = '" & strName & "'"
' Verify that they want to add the new City Name
If vbYes = MsgBox("City Name " & NewData & " is not defined. " & _
"Do you want to add this City Name?", vbYesNo + vbQuestion + vbDefaultButton2, _
gstrAppTitle) Then
' Open the AddCityCountry form and pass it the new value
DoCmd.OpenForm "AddCityCountry", DataMode:=acFormAdd, WindowMode:=acDialog, _
OpenArgs:=strName
' Code will wait until "AddCityCountry" form closes - now verify that it got added!
If IsNull(DLookup("MainCityName", "MainCity", strWhere)) Then
' Ooops
MsgBox "You failed to add a City Name that matched what you entered. " & _
"Please try again.", gstrAppTitle
' Tell Access we handled the error, but cancel the update
Response = acDataErrContinue '<====== I DONT SEE THIS MSGBOX IN ANY SITUATION
Else
' Tell Access new data was added
Response = acDataErrAdded
End If
Else
' Don't want to add what they typed - show standard error message
MsgBox "This entry could not be found" & vbCrLf & _
"Please choose an item from the drop down list", vbInformation, "SAC Pakistan Guide"
Response = acDataErrContinue
cboResidenceCity.SetFocus
Me.Undo
End If
End Sub
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Kahlid-
John,
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
That should work as long as gstrAppTitle has what you want to display.
The help file options are really obsolete. The MsgBox command was originally created when Windows was still using .hlp files. You needed a special utility to convert something like a Word document into help file format. The context argument would point to a specific numeric help topic within the file to display it in a separate help window. Help is now all xml-based, and I don't think Windows supports the old .hlp files anymore.
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 7, 2017, at 2:06 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
John,
I have did as following and working, is it OK ?
Private Sub cboResidenceCity_NotInList(NewData As String, Response As Integer)
Dim strName As String, strWhere As String
gstrAppTitle = "SAC Pakistan Guide - Information" ' <======
' User typed in a City Name that's not in the list
strName = NewData
' Build the verification search string
strWhere = "[MainCityName] = '" & strName & "'"
' Verify that they want to add the new City Name
If vbYes = MsgBox("City Name " & NewData & " is not defined. " & _
"Do you want to add this City Name?", vbYesNo + vbQuestion + vbDefaultButton2, _
gstrAppTitle) Then
...
...
End Sub
By the way how does a help file is created ?
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
MsgBox syntax is:
MsgBox ( prompt [, buttons ] [, title ] [, helpfile ] [, context ] )
So, gstrAppTitle should be pointing to a help file. If you want to just display "SAC Pakistan Guide - Information" as the title, remove the last parameter.
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 7, 2017, at 9:15 AM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
__._,_.___
Posted by: khalidtanweerburrah@yahoo.com
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (23) |
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