Combo Box (1 Viewer)

sparklegrrl

Registered User.
Local time
Today, 07:12
Joined
Jul 10, 2003
Messages
124
Good afternoon all,

I need a little help. I'm trying to set a combo box with cities in it so that users can add data, it will check for duplicates and refresh itself. I'm on Access 2016.

Is there any way to do this?

Thanks in advance for your help.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:12
Joined
Oct 29, 2018
Messages
21,449
Hi,

Lots of ways to do it. For example, you can use the Not In List event to add new cities.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,228
here is a sample for you to study.
 

Attachments

  • cities.zip
    22.2 KB · Views: 43

Galaxiom

Super Moderator
Staff member
Local time
Today, 16:12
Joined
Jan 20, 2009
Messages
12,851
I'm trying to set a combo box with cities in it so that users can add data, it will check for duplicates and refresh itself.

Be prepared for multiple misspellings of the cities being entered.
 

Cronk

Registered User.
Local time
Today, 16:12
Joined
Jul 4, 2013
Messages
2,771
"...multiple misspellings..."

That's why I limit the ability to add new entries to one or two of the more senior/responsible users.
 

Dreamweaver

Well-known member
Local time
Today, 07:12
Joined
Nov 28, 2005
Messages
2,466
This is what I use for all my lists

put this in the not in list :
Response = FillListsOne(NewData, "LtblCityLookup", "City")
If Response = acDataErrContinue Then
RunCommand acCmdUndo
End If




Put this in a module
Under Option Explicit add
Private m_rst As Recordset
Private m_IntNew As Integer
Private Const m_strMsg As String = " Is Not An Item In The List Would You Like To Add It"
Private Const m_strUndoMsg As String = " Is Not In the List Undoing Entry"
Private Const m_strTitle As String = "Undoing Invalid Entry"

'I Use theses as I have a number of list funtions


Public Function FillListsOne(StrItem As String, StrTable As String, _
StrField As String) As Integer
On Error GoTo Err_HandleErr
m_IntNew = MsgBox(StrItem & m_strMsg _
, vbInformation + vbYesNo, "Item Not In List")
If m_IntNew = vbYes Then
Set m_rst = CurrentDb.OpenRecordset(StrTable)
m_rst.AddNew
m_rst(StrField) = StrItem
m_rst.Update
FillListsOne = acDataErrAdded
Else
MsgBox StrItem & m_strUndoMsg, , m_strTitle
FillListsOne = acDataErrContinue
End If

Exit_HandleErr:
m_rst.Close
Set m_rst = Nothing
Exit Function

Err_HandleErr:
Select Case Err.Number
Case 91
Exit Function
Case Else
MsgBox "The Following Error Has Occured & vbCrLf" _
& "Error Number: " & Err.Number & vbCrLf & "Error Description" _
& vbCrLf & Err.Description
Resume Exit_HandleErr
Resume
End Select

End Function
 
Last edited:

Dreamweaver

Well-known member
Local time
Today, 07:12
Joined
Nov 28, 2005
Messages
2,466
I also set a dropdown default for my lists and sort ascending so as the user adds letters the list responds like a lookup. Hope it helps
 

mike60smart

Registered User.
Local time
Today, 07:12
Joined
Aug 6, 2017
Messages
1,908
Hi MickJav

You say:-

"put this in the not in list :
Response = FillListsOne(NewData, "LtblCityLookup", "City")
If Response = acDataErrContinue Then
RunCommand acCmdUndo
End If"

Would you have this format for every Not In List Event and just amend the First line of Code??
 

Dreamweaver

Well-known member
Local time
Today, 07:12
Joined
Nov 28, 2005
Messages
2,466
Hi MickJav

Response = FillListsOne(NewData, "LtblCityLookup", "City")
If Response = acDataErrContinue Then
RunCommand acCmdUndo
End If"

Would you have this format for every Not In List Event and just amend the First line of Code??

Just update the Ltblcitylookup for your table and city for your field name if will work in any combo box you need to add a single item to the table
 

Cronk

Registered User.
Local time
Today, 16:12
Joined
Jul 4, 2013
Messages
2,771
A word of caution in the code in the code for FillListsOne.

I don't see any variables declared in the code. Either Option Explicit is not used in the module or variables have been declared at module level. Both are not good practice.
 

Dreamweaver

Well-known member
Local time
Today, 07:12
Joined
Nov 28, 2005
Messages
2,466
A word of caution in the code in the code for FillListsOne.

I don't see any variables declared in the code. Either Option Explicit is not used in the module or variables have been declared at module level. Both are not good practice.


Under Option Explicit add
Private m_rst As Recordset
Private m_IntNew As Integer
Private Const m_strMsg As String = " Is Not An Item In The List Would You Like To Add It"
Private Const m_strUndoMsg As String = " Is Not In the List Undoing Entry"
Private Const m_strTitle As String = "Undoing Invalid Entry"



Public Function FillListsOne(StrItem As String, StrTable As String, _
StrField As String) As Integer


Maybe you should read the code I always use Option Explicit
 

Users who are viewing this thread

Top Bottom