G
Guest
Please can anyone advise as I'm a bit stuck,
I need to use the combo box on customer name in a subform to add new sites -
to ensure that if a customer has many sites the same customer name format is
used each time - however I can't get the update in the combo box to work when
a new customer name is required.
I've read through various ways on how to do this but I can't find a solution
for how to solve my problem so here goes,
I have used the code on NotInList as below which worked except for the fact
that it seems to save this single value each time a new one is entered.
This throws up errors due to the fact that all of the other fields are
mandatory or if I take this off then because the site ID is a primary key and
it can't be null.
How can I get this to run and stick to the current entry so that I can
update the whole record and then it gets added to the table?
for information:
I do also have a Goto new Record on the on Open of the subform
Private Sub Customer_Name_Combo_NotInList(NewData As String, Response As
Integer)
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_UNDOFIELD, , A_MENU_VER20
Dim db As DAO.Database
Set db = CurrentDb
'Ask the user if they want to add to the list
If MsgBox("Do you want to add this Customer Name?", vbYesNo + vbQuestion,
"Add new value?") = vbYes Then
'The user clicked Yes - add the new value
db.Execute "INSERT INTO TblCustomerProfiles (CustomerName) VALUES (""" &
NewData & """)", dbFailOnError
'Tell Access you've added the new value
Response = acDataErrAdded
Else
'The user clicked No - discard the new value
Me.Customer_Name_Combo.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue
End If
db.Close
Set db = Nothing
End Sub
Thanks for advice - it's all a bit new!
I need to use the combo box on customer name in a subform to add new sites -
to ensure that if a customer has many sites the same customer name format is
used each time - however I can't get the update in the combo box to work when
a new customer name is required.
I've read through various ways on how to do this but I can't find a solution
for how to solve my problem so here goes,
I have used the code on NotInList as below which worked except for the fact
that it seems to save this single value each time a new one is entered.
This throws up errors due to the fact that all of the other fields are
mandatory or if I take this off then because the site ID is a primary key and
it can't be null.
How can I get this to run and stick to the current entry so that I can
update the whole record and then it gets added to the table?
for information:
I do also have a Goto new Record on the on Open of the subform
Private Sub Customer_Name_Combo_NotInList(NewData As String, Response As
Integer)
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_UNDOFIELD, , A_MENU_VER20
Dim db As DAO.Database
Set db = CurrentDb
'Ask the user if they want to add to the list
If MsgBox("Do you want to add this Customer Name?", vbYesNo + vbQuestion,
"Add new value?") = vbYes Then
'The user clicked Yes - add the new value
db.Execute "INSERT INTO TblCustomerProfiles (CustomerName) VALUES (""" &
NewData & """)", dbFailOnError
'Tell Access you've added the new value
Response = acDataErrAdded
Else
'The user clicked No - discard the new value
Me.Customer_Name_Combo.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue
End If
db.Close
Set db = Nothing
End Sub
Thanks for advice - it's all a bit new!