ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   add to a dynamic list (https://www.excelbanter.com/excel-programming/358875-add-dynamic-list.html)

L Scholes

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


GS

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

L Scholes

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.


L Scholes

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.


GS

add to a dynamic list
 
Assuming cboDealer is a ComboBox control, try

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

Regards,
GS

Tom Ogilvy

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.




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com