Connecting Tech Pros Worldwide Help | Site Map

setting .notinlist from VBA

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 10:03 AM
whilstiwait@gmail.com
Guest
 
Posts: n/a
Default setting .notinlist from VBA

I have a form containing a number of unbound combo boxes in three
columns. Each column has boxes named "aaaa0", "aaaa1", etc. Using
syntax like:

With Forms(Me.Form.Name).Controls("txtTechnology" & i)
.AfterUpdate = "=txtTechnology_Change(" & i & ")"
.OnEnter = "=txtTechnology_OnEnter(" & i & ")"
End With

I can set events to a common routine for all the boxes, and in the
events use the passed ID (i) to reference the data in the combo box
that fired the event (using "with...")

I can set a .notinlist event, using syntax like:

.OnNotInList = "=txtTechnology_NotInList(" & i & ",0)"

which I know is not correct, but the event does fire. The ID doesn't
pass in.

The question: what syntax should I use on the .notinlist line to match
up the the (newData, Response) format of the notinlist event?

Thanks,

Keith


  #2  
Old November 13th, 2005, 10:05 AM
Wayne Morgan
Guest
 
Posts: n/a
Default Re: setting .notinlist from VBA

The problem is, as you note, getting the functionallity of the built-in
parameters. If the NotInList routine is fairly complicated or a lot of
typing, you can do what you are wanting, but you'll need to use the
NotInList event to call the consolidated routine. Set the On NotInList to
[Event Procedure] then in the event procedure, pass the information to your
consolidated routine. You should even be able to pass a value for Response
to the consolidated routine. If you pass it ByRef and change it in the
consolidated routine, you will get the change back in the calling event. You
would then assign this changed value to Response once you return from the
consolidated routine.

Example:
Private Sub cboMyCombo1_NotInList(NewData As String, Response As Integer)
Dim intResponse As Integer, strComboName As String
'Remove the _NotInList to get the combo name
strComboName = Me.ActiveControl.Name
MyNotInList(NewData, intResponse, strComboName)
Response = intResponse
End Sub

Public Sub MyNotInList(NewData As String, ByRef intResponse As Integer,
strCombo As String)
'Do your add routine here.
'Set the value of intResponse before you exit, just as you would set the
value
'for Response in the normal sub.
'(intResponse = acDataErrAdded or intResponse = acDataErrContinue)
End Sub

The normal way of passing data in VBA is ByRef, so the ByRef keyword may not
be needed. However, it also shouldn't hurt anything and will serve as a
reminder of what you're trying to do.

--
Wayne Morgan
MS Access MVP


<whilstiwait@gmail.com> wrote in message
news:1116421357.708975.273840@g49g2000cwa.googlegr oups.com...[color=blue]
>I have a form containing a number of unbound combo boxes in three
> columns. Each column has boxes named "aaaa0", "aaaa1", etc. Using
> syntax like:
>
> With Forms(Me.Form.Name).Controls("txtTechnology" & i)
> .AfterUpdate = "=txtTechnology_Change(" & i & ")"
> .OnEnter = "=txtTechnology_OnEnter(" & i & ")"
> End With
>
> I can set events to a common routine for all the boxes, and in the
> events use the passed ID (i) to reference the data in the combo box
> that fired the event (using "with...")
>
> I can set a .notinlist event, using syntax like:
>
> .OnNotInList = "=txtTechnology_NotInList(" & i & ",0)"
>
> which I know is not correct, but the event does fire. The ID doesn't
> pass in.
>
> The question: what syntax should I use on the .notinlist line to match
> up the the (newData, Response) format of the notinlist event?
>
> Thanks,
>
> Keith
>[/color]


  #3  
Old November 13th, 2005, 10:09 AM
whilstiwait@gmail.com
Guest
 
Posts: n/a
Default Re: setting .notinlist from VBA

Thanks for the suggestion.

Even though it's not correctly formed it does work. I set the ID on the
Enter event and the NotInList picks it up. I was hoping there would be
an easy way to set the event programmatically - it's the only one I've
found, so far, that has this problem.

Keith

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.