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 ComboBox (txtSignature) on a userform that gets it's
information from a dynamic list (DealerName). If I enter a name that is
not in DealerName, I get an error message "Run-time error '381': Could
not get the List property. Invalid property array index." Instead of
this message, I would like to give the user a message allowing three
options:
1) add the new name to the dynamic list and enter the new name onto the
form as if the name were there all along;
2) add as if it were in the list, but don't add it to the list;
3) cancel and do nothing but clear the user form.
Using vbaMsgBoxYesNoCancel, I just don't know how to code it where
above option 1 = yes, 2 = no, 3 = cancel in the MsgBox
Does anybody have the code for this?
Thanks in advance

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

You can test the user response to the MsgBox as follows:

Dim vAns As Variant

vAns = MsgBox("Do you want to add it to the list?", vbYesNoCancel)

Select Case vAns
Case Is = vbYes
'add it to the list...
Case Is = vbNo
'do something as if it was added to the list...
Case is = vbCancel
'do something else...
End Select

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

As someone else on here likes to say "ask a specific question, get a
specific answer." I should have been more specific: when I attempt to
enter a name not already in the list I get a "debugger message" that
highlights the following code:

ws.Cells(iRow, 2).Value = Me.cboDealer.List(lDealer, 1)

The code you provided looks like what I need, but how do I enter it
relative to my code? Will I need an "On Error" command?
Thank you very much.

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

Assuming cboDealer is a ComboBox control, try

ws.Cells(iRow, 2).Value = Me.cboDealer.Value

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

As someone else on here likes to say "ask a specific question, get a
specific answer." I should have been more specific: when I attempt to
enter a name not already in the list I get a "debugger message" that
highlights the following code:

ws.Cells(iRow, 2).Value = Me.cboDealer.List(lDealer, 1)

The code you provided looks like what I need, but how do I enter it
relative to my code? Will I need an "On Error" command?
Thank you very much.



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

Avoid the error. Before trying to access the list, check the listindex and
see if it is valid.

with somecombobox
if .listindex = -1 and .value < "" then
' user has entered a value not in the list
else
v = .list(.listindex)
end if
End with

If you want to trap an error, you can use
On Error Resume Next
' code that may cause an error
if err.Number < 0 then
' an error has occured
Err.clear
else
' an error has not occured
end if
On Error goto 0

The reason you are not getting a pat answer is that a Combobox has several
settings involved here and most programming would be specific to what event,
when it is happening, how the userform is designed, what you are doing/trying
to do/ the user is doing/trying to do.

--
Regards,
Tom Ogilvy


"L Scholes" wrote:

As someone else on here likes to say "ask a specific question, get a
specific answer." I should have been more specific: when I attempt to
enter a name not already in the list I get a "debugger message" that
highlights the following code:

ws.Cells(iRow, 2).Value = Me.cboDealer.List(lDealer, 1)

The code you provided looks like what I need, but how do I enter it
relative to my code? Will I need an "On Error" command?
Thank you very much.


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
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
add to a dynamic list L Scholes Excel Programming 9 April 14th 06 01:18 AM
Dynamic list box Rafael[_3_] Excel Programming 1 December 30th 03 06:56 PM


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

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"