PC Review


Reply
Thread Tools Rate Thread

Adding New items to a combo box on the Fly.

 
 
=?Utf-8?B?TGVsZQ==?=
Guest
Posts: n/a
 
      2nd Sep 2006
The following code was supplied by Tina, and I found it useful, but I need a
bit of help tweaking it

> Private Sub td_empID_NotInList(NewData As String, Response As Integer)
>
> If MsgBox("Do you want to add this employee to the droplist?", _
> vbYesNo + vbDefaultButton2, "INITIALS NOT IN LIST") = vbYes Then
> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
> UCase(NewData)
> Response = acDataErrAdded
> Else
> Response = acDataErrContinue
> End If
>
> End Sub

--

When I tell it I want to add to the list, the data entry form pops open just
fine, and takes the new data. I then save the new data, and close the form.
When I return to the original drop down list, I continue to get the message
....Not on list, although The new entry now appears in the list. If I then
scroll to the item, the form accepts it and I can continue.

Obviously, this is a bit awkward.
How I can add the new item on the popup data entry form, close it, and have
my cursor be returned to the dropdown list with the new data already selected
and ready to go to the next field?

Thanks

Lele
 
Reply With Quote
 
 
 
 
Al Campagna
Guest
Posts: n/a
 
      2nd Sep 2006
Lele,
I think all that's needed is a Requery of your combo or listbox.
But...
This the Code I use in my sample file called NotInList Combobox (on my website below)
This adds the new value automatically... (using [State] as a NotInList value)

Private Sub cboState_NotInList(NewData As String, Response As Integer)
Dim sqlAddState As String, UserResponse As Integer
Beep
UserResponse = MsgBox("Do you want to add this value to the list?", vbYesNo)
If UserResponse = vbYes Then
sqlAddState = "Insert Into tblStates ([State]) values ('" & NewData & "')"
CurrentDb.Execute sqlAddState, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
--
hth
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions


"Lele" <(E-Mail Removed)> wrote in message
news:284CCBFF-E9C4-417A-A02E-(E-Mail Removed)...
> The following code was supplied by Tina, and I found it useful, but I need a
> bit of help tweaking it
>
>> Private Sub td_empID_NotInList(NewData As String, Response As Integer)
>>
>> If MsgBox("Do you want to add this employee to the droplist?", _
>> vbYesNo + vbDefaultButton2, "INITIALS NOT IN LIST") = vbYes Then
>> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
>> UCase(NewData)
>> Response = acDataErrAdded
>> Else
>> Response = acDataErrContinue
>> End If
>>
>> End Sub

> --
>
> When I tell it I want to add to the list, the data entry form pops open just
> fine, and takes the new data. I then save the new data, and close the form.
> When I return to the original drop down list, I continue to get the message
> ...Not on list, although The new entry now appears in the list. If I then
> scroll to the item, the form accepts it and I can continue.
>
> Obviously, this is a bit awkward.
> How I can add the new item on the popup data entry form, close it, and have
> my cursor be returned to the dropdown list with the new data already selected
> and ready to go to the next field?
>
> Thanks
>
> Lele



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      2nd Sep 2006
Unfortunately, Al, Lele requires additional information be added to the
table, so it is necessary to open a form.

Lele: I agree with Al that a Requery might solve the problem. Try:

DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
UCase(NewData)
Me.td_empID.Requery
Response = acDataErrAdded


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Al Campagna" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Lele,
> I think all that's needed is a Requery of your combo or listbox.
> But...
> This the Code I use in my sample file called NotInList Combobox (on my
> website below)
> This adds the new value automatically... (using [State] as a NotInList
> value)
>
> Private Sub cboState_NotInList(NewData As String, Response As Integer)
> Dim sqlAddState As String, UserResponse As Integer
> Beep
> UserResponse = MsgBox("Do you want to add this value to the list?",
> vbYesNo)
> If UserResponse = vbYes Then
> sqlAddState = "Insert Into tblStates ([State]) values ('" & NewData
> & "')"
> CurrentDb.Execute sqlAddState, dbFailOnError
> Response = acDataErrAdded
> Else
> Response = acDataErrContinue
> End If
> End Sub
> --
> hth
> Al Campagna
> Candia Computer Consulting - Candia NH
> http://home.comcast.net/~cccsolutions
>
>
> "Lele" <(E-Mail Removed)> wrote in message
> news:284CCBFF-E9C4-417A-A02E-(E-Mail Removed)...
>> The following code was supplied by Tina, and I found it useful, but I
>> need a
>> bit of help tweaking it
>>
>>> Private Sub td_empID_NotInList(NewData As String, Response As Integer)
>>>
>>> If MsgBox("Do you want to add this employee to the droplist?", _
>>> vbYesNo + vbDefaultButton2, "INITIALS NOT IN LIST") = vbYes Then
>>> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog,
>>> _
>>> UCase(NewData)
>>> Response = acDataErrAdded
>>> Else
>>> Response = acDataErrContinue
>>> End If
>>>
>>> End Sub

>> --
>>
>> When I tell it I want to add to the list, the data entry form pops open
>> just
>> fine, and takes the new data. I then save the new data, and close the
>> form.
>> When I return to the original drop down list, I continue to get the
>> message
>> ...Not on list, although The new entry now appears in the list. If I
>> then
>> scroll to the item, the form accepts it and I can continue.
>>
>> Obviously, this is a bit awkward.
>> How I can add the new item on the popup data entry form, close it, and
>> have
>> my cursor be returned to the dropdown list with the new data already
>> selected
>> and ready to go to the next field?
>>
>> Thanks
>>
>> Lele

>
>



 
Reply With Quote
 
Al Campagna
Guest
Posts: n/a
 
      3rd Sep 2006
Douglas,
That's a good idea. I think I'll add a "go to a 'New Record' form and add a record"
form to my NotInList sample file.
Thanks,
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:(E-Mail Removed)...
> Unfortunately, Al, Lele requires additional information be added to the table, so it is
> necessary to open a form.
>
> Lele: I agree with Al that a Requery might solve the problem. Try:
>
> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
> UCase(NewData)
> Me.td_empID.Requery
> Response = acDataErrAdded
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "Al Campagna" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Lele,
>> I think all that's needed is a Requery of your combo or listbox.
>> But...
>> This the Code I use in my sample file called NotInList Combobox (on my website below)
>> This adds the new value automatically... (using [State] as a NotInList value)
>>
>> Private Sub cboState_NotInList(NewData As String, Response As Integer)
>> Dim sqlAddState As String, UserResponse As Integer
>> Beep
>> UserResponse = MsgBox("Do you want to add this value to the list?", vbYesNo)
>> If UserResponse = vbYes Then
>> sqlAddState = "Insert Into tblStates ([State]) values ('" & NewData & "')"
>> CurrentDb.Execute sqlAddState, dbFailOnError
>> Response = acDataErrAdded
>> Else
>> Response = acDataErrContinue
>> End If
>> End Sub
>> --
>> hth
>> Al Campagna
>> Candia Computer Consulting - Candia NH
>> http://home.comcast.net/~cccsolutions
>>
>>
>> "Lele" <(E-Mail Removed)> wrote in message
>> news:284CCBFF-E9C4-417A-A02E-(E-Mail Removed)...
>>> The following code was supplied by Tina, and I found it useful, but I need a
>>> bit of help tweaking it
>>>
>>>> Private Sub td_empID_NotInList(NewData As String, Response As Integer)
>>>>
>>>> If MsgBox("Do you want to add this employee to the droplist?", _
>>>> vbYesNo + vbDefaultButton2, "INITIALS NOT IN LIST") = vbYes Then
>>>> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
>>>> UCase(NewData)
>>>> Response = acDataErrAdded
>>>> Else
>>>> Response = acDataErrContinue
>>>> End If
>>>>
>>>> End Sub
>>> --
>>>
>>> When I tell it I want to add to the list, the data entry form pops open just
>>> fine, and takes the new data. I then save the new data, and close the form.
>>> When I return to the original drop down list, I continue to get the message
>>> ...Not on list, although The new entry now appears in the list. If I then
>>> scroll to the item, the form accepts it and I can continue.
>>>
>>> Obviously, this is a bit awkward.
>>> How I can add the new item on the popup data entry form, close it, and have
>>> my cursor be returned to the dropdown list with the new data already selected
>>> and ready to go to the next field?
>>>
>>> Thanks
>>>
>>> Lele

>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?TGVsZQ==?=
Guest
Posts: n/a
 
      9th Sep 2006
I am trying to add values to my combo box called Patterns, on the fly. My
problem is the table of Patterns I am adding to requires both a PatternName
and a Manufacturer as primary fields for each record.

The code you provided has been very helpful and easy to both use and
understand. Thank-you:

Private Sub PatternName_NotInList(NewData As String, Response As Integer)
Dim sqlAddPattern As String, UserResponse As Integer
Beep
UserResponse = MsgBox("Do you want to add this Pattern to the list?", vbYesNo)
If UserResponse = vbYes Then
sqlAddPattern = "Insert Into Patterns ([PatternName]) values ('" &
NewData & "')"
CurrentDb.Execute sqlAddPattern, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If

End Sub

My problem is based on the fact that each pattern record requires both a
pattern name and a manufacturer designation. I am trying to do this by
selecting the manufacturer from a combo box before I go to the pattern combo
box. When I tab to the Pattern ComboBox and enter a new pattern name, I get
to the
point where it is ready to add the new name to the list, but if I try to
proceed I get a run time error 3058 primary or index field can not contain a
null value. The code line: CurrentDb.Execute sqlAddPattern, dbFailOnError is
highlighted

How can I modify the code so the manufacturer value i selected is also added
by the code?

Thanks so much for your help!!
--
Lele


"Al Campagna" wrote:

> Lele,
> I think all that's needed is a Requery of your combo or listbox.
> But...
> This the Code I use in my sample file called NotInList Combobox (on my website below)
> This adds the new value automatically... (using [State] as a NotInList value)
>
> Private Sub cboState_NotInList(NewData As String, Response As Integer)
> Dim sqlAddState As String, UserResponse As Integer
> Beep
> UserResponse = MsgBox("Do you want to add this value to the list?", vbYesNo)
> If UserResponse = vbYes Then
> sqlAddState = "Insert Into tblStates ([State]) values ('" & NewData & "')"
> CurrentDb.Execute sqlAddState, dbFailOnError
> Response = acDataErrAdded
> Else
> Response = acDataErrContinue
> End If
> End Sub
> --
> hth
> Al Campagna
> Candia Computer Consulting - Candia NH
> http://home.comcast.net/~cccsolutions
>
>
> "Lele" <(E-Mail Removed)> wrote in message
> news:284CCBFF-E9C4-417A-A02E-(E-Mail Removed)...
> > The following code was supplied by Tina, and I found it useful, but I need a
> > bit of help tweaking it
> >
> >> Private Sub td_empID_NotInList(NewData As String, Response As Integer)
> >>
> >> If MsgBox("Do you want to add this employee to the droplist?", _
> >> vbYesNo + vbDefaultButton2, "INITIALS NOT IN LIST") = vbYes Then
> >> DoCmd.OpenForm "frm01Employees_pop", , , , acFormAdd, acDialog, _
> >> UCase(NewData)
> >> Response = acDataErrAdded
> >> Else
> >> Response = acDataErrContinue
> >> End If
> >>
> >> End Sub

> > --
> >
> > When I tell it I want to add to the list, the data entry form pops open just
> > fine, and takes the new data. I then save the new data, and close the form.
> > When I return to the original drop down list, I continue to get the message
> > ...Not on list, although The new entry now appears in the list. If I then
> > scroll to the item, the form accepts it and I can continue.
> >
> > Obviously, this is a bit awkward.
> > How I can add the new item on the popup data entry form, close it, and have
> > my cursor be returned to the dropdown list with the new data already selected
> > and ready to go to the next field?
> >
> > Thanks
> >
> > Lele

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding items to a combo box Phrank Microsoft Excel Programming 2 3rd Dec 2006 08:16 PM
Adding Items To a combo Box LoveCandle Microsoft Excel Programming 4 7th Apr 2006 09:58 PM
Adding items to a combo box =?Utf-8?B?VFM=?= Microsoft VB .NET 6 8th Dec 2005 08:05 AM
Adding items in Combo box Bala Nagarajan Microsoft Dot NET Framework Forms 5 7th Nov 2005 08:29 AM
Adding Combo Box Items =?Utf-8?B?dmI=?= Microsoft VB .NET 3 13th Nov 2004 10:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 AM.