Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NotInList Multiple Field ComboBox 1

Status
Not open for further replies.

Elvis72

Technical User
Dec 6, 2007
211
0
0
US
I have searched and searched...can't find my way...

I have no problems with a one column notinlist function.

But I have one field that shows a combined combobox for Managers:

Which shows Last Name and First Name.

I cannot figure out how in the world to create and update for 2 fields?

Any direction is greatly appreciated!~
 
What is the row source for your combobox?
 
This is it:

SELECT TblManager.[Last Name], TblManager.[First Name] FROM TblManager ORDER BY [Last Name];
 
There is your problem already. Include the unique key for the person in a hidden column.
 
OK...updated my combobox recordsource to:

SELECT TblManager.ManagerID, TblManager.[Last Name], TblManager.[First Name] FROM TblManager ORDER BY [Last Name];

But this is still not pointing me in the direction to figure out how to update 2 fields?
 
This part works fine:

Private Sub Manager_NotInList(NewData As String, Response As Integer)

Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

If NewData = "" Then Exit Sub

Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then

DoCmd.OpenForm "FrmManager", , , , acAdd, acDialog, NewData
End If

End Sub

IT does not like:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
' If form's OpenArgs property has a value, assign the contents
' of OpenArgs to the CompanyName field. OpenArgs will contain
' a company name if this form is opened using the OpenForm
' method with an OpenArgs argument, as done in the Orders
' form's CustomerID_NotInList event procedure.
Me![FrmManager] = Me.OpenArgs
End If
End Sub

it can't find FrmManager?

 
You need:

Me![Name of the control that should have new data, txtSurname for example] = Me.OpenArgs

In your case, I would skip this bit for now, it will just make life more difficult. You would probably need to split the name into its various parts and put each part in the correct box.
 
OK...then how do you on close of that form update the table that managers is based?
 
The form should be linked to the managers table in the usual way. That is, the record source is set to a query on the managers table.
 
I think I my brain is turned off today because I am really confused..

I have my main form with the Managers ComboBox which has Last Name, First Name.

I have it where on not in list it opens FrmManager where I can enter the new person.

But when I close the form and I see the original main form the manager's combobox does not update.
 
Do you have Response=acDataErrAdded in there anywhere?
 
Nope...where would I put it???

I haven't done this in a really long time, but I don't remember it being so hard...then again...I'm older and my brain apparently isn't working so well...lol
 
After the code that opens your form. The link I posted has this code:

Code:
    ' Look for the customer the user created in the Customers form.
    Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & NewData & "'")
    If IsNull(Result) Then
       ' If the customer was not created, set the Response argument
       ' to suppress an error message and undo changes.
       Response = acDataErrContinue
       ' Display a customized message.
       MsgBox "Please try again!"
    Else
       ' If the customer was created, set the Response argument to
       ' indicate that new data is being added.
       Response = acDataErrAdded
    End If

:)


 
OK...here is what I have:

' Look for the customer the user created in the Customers form.
Result = DLookup("[Manager]", "TblManager", _
"[Manager]='" & NewData & "'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub

When I type:

Rogers Amber

In the Manager's Combobox the prompt comes up to add.

I click add and the FrmManager comes up, I type in Rogers and Amber in the respective fields and close the form.

It says Please Try Again...


 
I think we need to try something else here. There are a couple of possibilities. If you do not have many users creating managers at the same time and the ManagerID is an autonumber, you can use:

Result = DLookup("[ManagerID]", "TblManager", _
"[ManagerID]=DMax("[ManagerID]", "TblManager"))

If you do have a lot of creations, we can try another direction.
 
Well when I put that in the code it gives me a Compile Syntax Error?
 
Sorry.

Result = DLookup("[ManagerID]", "TblManager", "[ManagerID]=" _
& DMax("[ManagerID]", "TblManager"))
 
Good Morning, I hope your having a wonderfully fabulous day!~

I used the new code and it works!~ Yeah!~

But when I close the form that comes up it still says the that the data entered is not in list....AND when I drop down on the list for Manager on the form its there...BUT its not in the TblManager?

So, I'm thinking I am at some point telling it to add to a value list or rowsource?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top