473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Add record to table when "Not In List"

I'm trying to automate a combo box to add a record to the source table
if it's "Not In List". I've tried many different examples and none
have worked.

Combo Box Name = Combo24
Source Table Name = TblHandler
Source Field Name = HandlerLoginID (key column = HandlerID which is an
autonumber)

Thanks
Stan

Nov 7 '06 #1
5 6105
Per krwill:
>I'm trying to automate a combo box to add a record to the source table
if it's "Not In List". I've tried many different examples and none
have worked.

Combo Box Name = Combo24
Source Table Name = TblHandler
Source Field Name = HandlerLoginID (key column = HandlerID which is an
autonumber)

Thanks
Stan
Here's how I usually do it.

This is some *old* code... hence the "skipLine" instead of
just vbCrlf & vbCrlf, the Integer instead of Boolean and the
magic number "6" instead of vbYes.

Ignore the DebugStackPush, DebugStackPop, and BugAlert stuff - it's just
my own canned error trapping.

At the end of the chain, there's a modal dialog that solicits the new info
from the user and then sets a global semaphore if the user hits "Save"
and nothing abends.

I started cautioning my clients about this type of feature some years back
because with salutations, for instance, users wind up adding variations like
"Mr." "Mr" or "Mister". They tend to have something in mind and they
just don't check the dropdown list for near matches. Trivial, perhaps, with
salutations... but can get real messy with things like firm names, fund names
and so-forth.

-----------------------------------------------------------------------------
Private Sub cboSalutation_NotInList(NewData As String, Response As Integer)
debugStackPush Me.Name & ": cboDonorNameSalutati_NotInList"
On Error GoTo cboDonorNameSalutati_NotInList_err

Response = salutationRecNotInList(NewData)

cboDonorNameSalutati_NotInList_xit:
debugStackPop
On Error Resume Next
Exit Sub

cboDonorNameSalutati_NotInList_err:
bugAlert ""
Resume cboDonorNameSalutati_NotInList_xit
End Sub
-----------------------------------------------------------------------------
Function salutationRecNotInList(theNewData As String) As Integer
debugStackPush mModuleName & ": salutationRecNotInList"
On Error GoTo salutationRecNotInList_err

' Accepts: Data typed into combo box that does not match any of the dropdown's
' entries.
' Returns: An integer that tells the combo box what the result was.
' i.e. Did we add a new entry to the list or bail out...
'
' Notes: 1) Intended to be called by all combo boxes which present
' salutations (e.g. "Mr", "Mrs"...)

Dim myNewData As String

Dim skipLine As String
skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)

myNewData = theNewData

If MsgBox("Salutation " & Chr$(34) & myNewData & Chr$(34) & " does not exist."
& skipLine & "Would you like to add it?", 36, "Quick Add?") = 6 Then
If AddRecSalutation(myNewData) = True Then
salutationRecNotInList = DATA_ERRADDED
End If
End If

salutationRecNotInList_xit:
debugStackPop
On Error Resume Next
Exit Function

salutationRecNotInList_err:
bugAlert ""
Resume salutationRecNotInList_xit
End Function
-----------------------------------------------------------------------------
Function AddRecSalutation(theNewData As String) As Integer
debugStackPush mModuleName & ": AddRecSalutation"
On Error GoTo AddRecSalutation_err

' Accepts: New Salutation to be added
' Returns: TRUE or FALSE depending on whether user completed the process
' (they may have pressed the form's CANCEL button or just closed
' the form...)
' Sets: Same field as new salutation ("theNewData") came in on, in case user
' elected to modify the title during the add process

Dim skipLine As String
skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)

DoCmd.OpenForm "frmAddRecSalutation", , , , , A_DIALOG, theNewData
AddRecSalutation = gModalAddDialogOutcome

AddRecSalutation_xit:
debugStackPop
On Error Resume Next
Exit Function

AddRecSalutation_err:
bugAlert ""
Resume AddRecSalutation_xit
End Function
-----------------------------------------------------------------------------


--
PeteCresswell
Nov 8 '06 #2
Per (PeteCresswell):
>DoCmd.OpenForm "frmAddRecSalutation", , , , , A_DIALOG, theNewData
Oh yeah... and the modal dialog initializes itself from the .OpenArg that I pass
it.

The modal dialog might be overkill for most situations. It presents what the
user typed and gives the user a chance to clean it up (as in capitalization...).

OTOH, it then incurs the responsibility to check the lookup table again to make
sure the user hasn't changed the "mr" that they typed to "Mr.", which already
exists in the table...

So, instead of popping the modal dialog, you could just run an append query in
it's place.
--
PeteCresswell
Nov 8 '06 #3
Hi!

You could also use the classical example ( in the 'NotInList' event):

Dim lngKID As Long

If MsgBox("Cannot find " & Chr(13) _
& " -" & UCase(NewData) & Chr(13) _
"Add it?", vbYesNo + vbInformation) = vbYes Then

Response = acDataErrAdded

If IsNull(Me!Somefield) then
Me!Somefield.Text = ""
Else
lngKID = Me!Somefield
Me!Somefield = null
End If

DoCmd.OpenForm "SomeForm",
acNormal,,,acFormAdd,acDialog,NewData
Me!Somefield.Requery

If lngKID <0 Then Me!Somefield = lngKID
Else
Response = acDataErrContinue
RunCommand acCmdUndo
End If

Then in the retrieving form add:

Private Sub Form_Current()
On Error GoTo Err_FCU

If Not IsNull(Me.OpenArgs) Then
Me!Somefield = Me.OpenArgs
End If

+

Private Sub Form_Load()
On Error GoTo Err_FL

If IsNull(Me.OpenArgs) Then
Me!Somefield = Me.OpenArgs
End If

+

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_FO
Me!Somefield.SetFocus

This works great for me :-)

krwill skrev:
I'm trying to automate a combo box to add a record to the source table
if it's "Not In List". I've tried many different examples and none
have worked.

Combo Box Name = Combo24
Source Table Name = TblHandler
Source Field Name = HandlerLoginID (key column = HandlerID which is an
autonumber)

Thanks
Stan
Nov 8 '06 #4
Thanks that worked!

Nov 9 '06 #5
Thanks that worked!

Nov 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Durgee | last post by:
I have a "submit" button in a form that creates a record in my Filemaker database that works as it should. This is the HTML for it: <INPUT TYPE="SUBMIT" name="-New" VALUE="Add Record"> I...
9
by: Bob Alston | last post by:
I have a drop down combo box that gives the user to enter an item not in the list by adding it to the list. The list is a table. It works fine on Access2003 but fails on Access2002/XP. ON XP, it...
9
by: Susan Bricker | last post by:
I am currently using the OnDirty event of a Form to detect whether any fields have been modified. I set a boolean variable. Then, if the Close button is clicked before the Save button, I can put...
5
by: a | last post by:
Is there a performance hit if I have many "using" statements that are unnecessary? For example: using System.Collections; when nowhere in my code I'm using System.Collections namespace. I'm...
1
by: poppybush | last post by:
I am working on a windows application that allows a system administrator to assign users to specific software titles. Let's say that there are 5 available licenses for Visual Studio but 6 users...
2
by: mfilion | last post by:
Hey all, I have a problem with my the Form I built, hopefully someone here can help me out! I'm still a beginner, so bear with me! Here goes... The form contains many boxes, each of which...
8
jmoudy77
by: jmoudy77 | last post by:
Hi, I've got a form that allows a user to imput their flight data. I programmed a MsgBox into the save button that asks if the user wants to input another duty position for the flight. If no, the...
0
by: howkoss | last post by:
Hi, I've been very frustrated for 2 days trying to make this work. I started with a built-in template "Projects" that came with Access 2007. On the "Employee List" I can click on any cell and bring...
3
dlite922
by: dlite922 | last post by:
Hey guys, My brains asleep and I don't know what's wrong with my session class. I'm over riding session with sesstion_set_save_handler() in a class; When in my member functions (open,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.