L
Lele
I am working on adding values to a combo box on the fly. The combo box is on
a form which also has a sub form connected in a one to many relationship. I
am sucessfully using the following great code from Ken Sheridan with help
from Terry Kreft, but now I need to get the sub form working right. (see
below)
I need to amend the code so when I add the values to the main form through
the combo box, a new blank record is prepared and ready to recieve infomation
for the sub form. The subForm is called Colors has two fields, an
autoIdNumber and Color. Right now when I run the code, I get an error message
"Your changes were not sucessful because they would create duplicate
values...etc. I believe that what is happening is a new autonumber is not
being created on the subform (as it needs to be) so there is a duplicate
value, a violation and I can not create the new record.
Any help is greatly appreciated.
Dim sqlAddPattern As String, strMessage As String
Dim UserResponse As Integer
Dim ctrl as Control
On Error Goto Err_Handler
Set ctrl = Me.ActiveControl
Beep
strMessage = "Do you want to add this Pattern to the list?"
UserResponse = MsgBox(strMessage, vbYesNo+ vbQuestion, "New Pattern")
If UserResponse = vbYes Then Then
If Not IsNull(Me.Manufacturer) then
sqlAddPattern = "INSERT INTO Patterns (PatternName, Manufacturer) "
& _
"VALUES (""" & NewData & """,""" & Me.Manufacturer & """)"
CurrentDb.Execute sqlAddPattern, dbFailOnError
Response = acDataErrAdded
Else
strMessage = "A manufacturer must be selected first."
MsgBox strMessage, vbExclamation, "Invalid Operation"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
Exit_Here:
Exit Sub
Err_Handler:
Response = acDataErrContinue
strMessage = Err.Description & " (" & Err.Number & ")"
MsgBox strMessage, vbExclamation, "Error"
Resume Exit_Here
End Sub
a form which also has a sub form connected in a one to many relationship. I
am sucessfully using the following great code from Ken Sheridan with help
from Terry Kreft, but now I need to get the sub form working right. (see
below)
I need to amend the code so when I add the values to the main form through
the combo box, a new blank record is prepared and ready to recieve infomation
for the sub form. The subForm is called Colors has two fields, an
autoIdNumber and Color. Right now when I run the code, I get an error message
"Your changes were not sucessful because they would create duplicate
values...etc. I believe that what is happening is a new autonumber is not
being created on the subform (as it needs to be) so there is a duplicate
value, a violation and I can not create the new record.
Any help is greatly appreciated.
Dim sqlAddPattern As String, strMessage As String
Dim UserResponse As Integer
Dim ctrl as Control
On Error Goto Err_Handler
Set ctrl = Me.ActiveControl
Beep
strMessage = "Do you want to add this Pattern to the list?"
UserResponse = MsgBox(strMessage, vbYesNo+ vbQuestion, "New Pattern")
If UserResponse = vbYes Then Then
If Not IsNull(Me.Manufacturer) then
sqlAddPattern = "INSERT INTO Patterns (PatternName, Manufacturer) "
& _
"VALUES (""" & NewData & """,""" & Me.Manufacturer & """)"
CurrentDb.Execute sqlAddPattern, dbFailOnError
Response = acDataErrAdded
Else
strMessage = "A manufacturer must be selected first."
MsgBox strMessage, vbExclamation, "Invalid Operation"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
Exit_Here:
Exit Sub
Err_Handler:
Response = acDataErrContinue
strMessage = Err.Description & " (" & Err.Number & ")"
MsgBox strMessage, vbExclamation, "Error"
Resume Exit_Here
End Sub