Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default add to a dynamic list

I have a user form that I have adapted to add information to a
data base. One of the fields (dealer) uses a combobox to select a
dealer name from a dynamic list. Right now, if the user tries to enter
a dealer name that is not in the dynamic list "DealerList" I get an
error message.
I want a message box that asks if the user wants to add the new
name to "DealerList," and if the user selects "Yes," the name is added
to "DealerList" (so the new name is available next time) and the form
continues adding the information to the database; if the user selects
"No," the name is not added to "DealerList" but the information is
still added to the database.
The question is: What code do I need to add and where. Let me know
if I need to paste my code here for you to evaluate.

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default add to a dynamic list

Please post your existing code. That will help and save time.

TIA
--
AP

"L Scholes" a écrit dans le message de
oups.com...
I have a user form that I have adapted to add information to a
data base. One of the fields (dealer) uses a combobox to select a
dealer name from a dynamic list. Right now, if the user tries to enter
a dealer name that is not in the dynamic list "DealerList" I get an
error message.
I want a message box that asks if the user wants to add the new
name to "DealerList," and if the user selects "Yes," the name is added
to "DealerList" (so the new name is available next time) and the form
continues adding the information to the database; if the user selects
"No," the name is not added to "DealerList" but the information is
still added to the database.
The question is: What code do I need to add and where. Let me know
if I need to paste my code here for you to evaluate.

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default add to a dynamic list

Private Sub cmdAdd_Click()
Dim lRow As Long
Dim lDealer As Long
Dim ws As Worksheet
Set ws = Worksheets("DealerData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

lDealer = Me.cboDealer.ListIndex

'check for a Dealer name
If Trim(Me.cboDealer.Value) = "" Then
Me.cboDealer.SetFocus
MsgBox "Please enter a Dealer Name."
Exit Sub
End If
If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If

'copy the data to the database
'ws.Cells(iRow, 1).Value = Me.txtbadge.Value
ws.Cells(iRow, 1).Value = Me.cboDealer.Value
ws.Cells(iRow, 2).Value = Me.cboDealer.List(lDealer, 1)
ws.Cells(iRow, 2).Value = Me.cboSignature.Value
ws.Cells(iRow, 3).Value = Me.txtPO.Value
ws.Cells(iRow, 4).Value = Me.txtInvoice.Value
ws.Cells(iRow, 5).Value = Me.txtDate.Value
ws.Cells(iRow, 6).Value = Me.txtDue.Value
'End With

'clear the data
Me.cboDealer.Value = ""
Me.cboSignature.Value = ""
Me.txtDate.Value = "" 'Format(Date, "Medium Date")
Me.txtPO.Value = ""
Me.txtDue.Value = ""
Me.txtInvoice.Value = ""
Me.cboDealer.SetFocus

End Sub
'cboPart = cboDealer A1
'cboLocation = cboSignature B2
'add txtPO & txtInvoice C3 & D4
'txtDate = txtDate E5
'txtQty = txtDue F6
Private Sub cmdClose_Click()
Unload Me
End Sub



Private Sub UserForm_Initialize()
Dim cDealer As Range
Dim cSig As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")

For Each cDealer In ws.Range("DealerList")
With Me.cboDealer
.AddItem cDealer.Value
.List(.ListCount - 1, 1) = cDealer.Offset(0, 1).Value
End With
Next cDealer

For Each cSig In ws.Range("Signature")
With Me.cboSignature
.AddItem cSig.Value
.List(.ListCount - 1, 1) = cSig.Offset(0, 1).Value
End With
Next cSig

Me.txtDate.Value = ""
Me.txtDue.Value = ""
Me.txtPO.Value = ""
Me.txtInvoice = ""
Me.cboDealer.SetFocus

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default add to a dynamic list

I have yet to use this but if I remember correctly the error is normal. I
think there is an "On Not in List" event handler that can be triggered. In
the event handling the record is added and the combobox is either reloaded
or the entry inserted into the combo box list.

In other words, the entry is not automatic.

Now, listen to others first!

--
My handle should tell you enough about me. I am not an MVP, expert, guru,
etc. but I do like to help.


"L Scholes" wrote in message
ups.com...
Private Sub cmdAdd_Click()
Dim lRow As Long
Dim lDealer As Long
Dim ws As Worksheet
Set ws = Worksheets("DealerData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

lDealer = Me.cboDealer.ListIndex

'check for a Dealer name
If Trim(Me.cboDealer.Value) = "" Then
Me.cboDealer.SetFocus
MsgBox "Please enter a Dealer Name."
Exit Sub
End If
If Trim(Me.txtPO.Value) = "" Then
Me.txtPO.SetFocus
MsgBox "Please enter a Purchase Order Number."
Exit Sub
End If

'copy the data to the database
'ws.Cells(iRow, 1).Value = Me.txtbadge.Value
ws.Cells(iRow, 1).Value = Me.cboDealer.Value
ws.Cells(iRow, 2).Value = Me.cboDealer.List(lDealer, 1)
ws.Cells(iRow, 2).Value = Me.cboSignature.Value
ws.Cells(iRow, 3).Value = Me.txtPO.Value
ws.Cells(iRow, 4).Value = Me.txtInvoice.Value
ws.Cells(iRow, 5).Value = Me.txtDate.Value
ws.Cells(iRow, 6).Value = Me.txtDue.Value
'End With

'clear the data
Me.cboDealer.Value = ""
Me.cboSignature.Value = ""
Me.txtDate.Value = "" 'Format(Date, "Medium Date")
Me.txtPO.Value = ""
Me.txtDue.Value = ""
Me.txtInvoice.Value = ""
Me.cboDealer.SetFocus

End Sub
'cboPart = cboDealer A1
'cboLocation = cboSignature B2
'add txtPO & txtInvoice C3 & D4
'txtDate = txtDate E5
'txtQty = txtDue F6
Private Sub cmdClose_Click()
Unload Me
End Sub



Private Sub UserForm_Initialize()
Dim cDealer As Range
Dim cSig As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")

For Each cDealer In ws.Range("DealerList")
With Me.cboDealer
.AddItem cDealer.Value
.List(.ListCount - 1, 1) = cDealer.Offset(0, 1).Value
End With
Next cDealer

For Each cSig In ws.Range("Signature")
With Me.cboSignature
.AddItem cSig.Value
.List(.ListCount - 1, 1) = cSig.Offset(0, 1).Value
End With
Next cSig

Me.txtDate.Value = ""
Me.txtDue.Value = ""
Me.txtPO.Value = ""
Me.txtInvoice = ""
Me.cboDealer.SetFocus

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default add to a dynamic list

I want a "new name" entry to ask if I want to:
#1 enter the name into the database BUT NOT to the source dynamic
list (DealerList);
#2 enter the name into the database AND into the source list;
#3 cancel and do nothing.
I'm not sure how to use an "On Not in List" event handler, I've never
heard of it???
Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default add to a dynamic list

Look at the properties of the Combo Box. Select the events tab. Look in
the list you will find it.

What you want probably can't be done without writing VBA code for the event
handler. Check out the Northwinds database and see if it has a combo box
that allows entering data and use their code if it does.

Another option would be to search for the event name and look for sample
code. As I stated before, I have yet to need that feature.

--
My handle should tell you enough about me. I am not an MVP, expert, guru,
etc. but I do like to help.


"L Scholes" wrote in message
ups.com...
I want a "new name" entry to ask if I want to:
#1 enter the name into the database BUT NOT to the source dynamic
list (DealerList);
#2 enter the name into the database AND into the source list;
#3 cancel and do nothing.
I'm not sure how to use an "On Not in List" event handler, I've never
heard of it???
Thanks



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default add to a dynamic list

Because there is no such event.

--
Regards,
Tom Ogilvy




"L Scholes" wrote:

I want a "new name" entry to ask if I want to:
#1 enter the name into the database BUT NOT to the source dynamic
list (DealerList);
#2 enter the name into the database AND into the source list;
#3 cancel and do nothing.
I'm not sure how to use an "On Not in List" event handler, I've never
heard of it???
Thanks


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
List vs Dynamic Range Name dee Excel Discussion (Misc queries) 2 November 27th 08 06:00 PM
Dynamic top 20 list Xhawk57 Excel Discussion (Misc queries) 4 November 5th 08 05:41 PM
Dynamic List kevin Excel Worksheet Functions 1 July 16th 07 01:12 PM
Changing named Validation list to Dynamic list. GlenC Excel Discussion (Misc queries) 1 July 20th 06 11:49 PM
Dynamic list box Rafael[_3_] Excel Programming 1 December 30th 03 06:56 PM


All times are GMT +1. The time now is 11:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"