Guernsey Gaz
Guernsey Gaz
- Local time
- Today, 23:22
- Joined
- May 15, 2008
- Messages
- 17
Hi All,
I have a db that has a table called tblCountryCity it has two columns the first being the Country the second being the City The table is not linked to anything as it is just used to get Country and City into other tables. The Country field has many duplicates, not a problem.
I have a couple of forms that allow users to Add New contacts and other things.
On each of these forms I have two Cascading combo boxes, 1 for the country, once the user has selected the country the second combo gives a list of cities only for that country. I have no problems there.
If a Country is typed in and is not in the countrycity table I can get it to add using the following code.
Private Sub cboCountry_NotInList(NewData As String, Response As Integer)
On Error GoTo cboCountry_NotinList_Error
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Country " & " '" & NewData & " '" & _
" is not currently listed in the Country Table." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Country")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tblCountryCity([Country]) " & "VALUES ('" & NewData & " ' );"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new Country" & " '" & NewData & " '" & "has been add to the list. " _
, vbInformation, "Country"
Response = acDataErrAdded
Else
MsgBox "Please choose a Country from the list." _
, vbInformation, " Country"
Response = acDataErrContinue
End If
cboCountry_NotInList_Exit: _
Exit Sub
cboCountry_NotInList_Error:
MsgBox Err.Description, vbCritical, "Error"
Resume cboCountry_NotInList_Exit
End Sub
This is fired with the NotInList Event for the cboCountry
OK heres the bit I got problems with, obviously if I add a new country to the list I am not going to have the city so if I type in the city then I want it to add it to the city field in the table... I have tried just copying the code and changing the fields about but it dosn't work. I can get either one without the other ie if I go straight to cboCity I can add it to the list but there is nothing in the country field next to the new city
Question: When I add a new Country via the cboCountry can I get the cboCity to add the new City?
Any help helps
Gaz
I have a db that has a table called tblCountryCity it has two columns the first being the Country the second being the City The table is not linked to anything as it is just used to get Country and City into other tables. The Country field has many duplicates, not a problem.
I have a couple of forms that allow users to Add New contacts and other things.
On each of these forms I have two Cascading combo boxes, 1 for the country, once the user has selected the country the second combo gives a list of cities only for that country. I have no problems there.
If a Country is typed in and is not in the countrycity table I can get it to add using the following code.
Private Sub cboCountry_NotInList(NewData As String, Response As Integer)
On Error GoTo cboCountry_NotinList_Error
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Country " & " '" & NewData & " '" & _
" is not currently listed in the Country Table." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Country")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tblCountryCity([Country]) " & "VALUES ('" & NewData & " ' );"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new Country" & " '" & NewData & " '" & "has been add to the list. " _
, vbInformation, "Country"
Response = acDataErrAdded
Else
MsgBox "Please choose a Country from the list." _
, vbInformation, " Country"
Response = acDataErrContinue
End If
cboCountry_NotInList_Exit: _
Exit Sub
cboCountry_NotInList_Error:
MsgBox Err.Description, vbCritical, "Error"
Resume cboCountry_NotInList_Exit
End Sub
This is fired with the NotInList Event for the cboCountry
OK heres the bit I got problems with, obviously if I add a new country to the list I am not going to have the city so if I type in the city then I want it to add it to the city field in the table... I have tried just copying the code and changing the fields about but it dosn't work. I can get either one without the other ie if I go straight to cboCity I can add it to the list but there is nothing in the country field next to the new city
Question: When I add a new Country via the cboCountry can I get the cboCity to add the new City?
Any help helps
Gaz