F
Fred Boer
Greetings!
I am working using the NotInList event of a combobox to pop up a dialogue
form. I use the popup form to add records to the table upon which the
combobox is based. On the popup form I have two command buttons:
"Undo/Close" and "Insert/Close". Code is reproduced below. This has been
working for me, however, I have discovered a problem: if the user has
actually entered all the appropriate data and then chooses neither of these
command buttons, but instead clicks the control box "X", (and no, I never
thought to try this myself! <g>), the data is inserted into the table. This
isn't what I want, since, to me at least, "X"ing out of the window would
logically mean "discard the data". Is there any way to deal with this
besides disabling the control box? I'd like to avoid changing the standard
windows UI...
Thanks!
Fred Boer
P.S. (For you ADH owners...) I am looking in the Access Developers Handbook
(2002), and I see a section on "Creating Pop-up Forms" in Chapter 8. Is this
a better approach? I must confess that I find the ADH a *wee* bit cryptic;
but I'm willing to give it a go if it is a better solution...
Code to open popup form:
Dim mbrResponse As VbMsgBoxResult
Dim strMsg As String
Dim db As Database, sSQL As String
strMsg = NewData & " isn't an existing author. " & "Add a new author?"
mbrResponse = MsgBox(strMsg, vbYesNo + vbQuestion, "Invalid Author")
Select Case mbrResponse
Case vbYes
DoCmd.OpenForm "Frm_InsertAuthor", _
DataMode:=acFormAdd, _
WindowMode:=acDialog
If ISLOADED("Frm_InsertAuthor") Then
Response = acDataErrAdded
DoCmd.Close acForm, "Frm_InsertAuthor"
Else
Response = acDataErrContinue
End If
Me.cboAuthor.Requery
Case vbNo
Response = acDataErrContinue
End Select
End Sub
Undo/Close:
Private Sub cmdUndo_Click()
Me.Undo
DoCmd.Close
End Sub
Insert/Close:
Dim db As Database, sSQL As String
Dim intNewAuthorID As Integer
If Me.Dirty = True Then Me.Dirty = False
intNewAuthorID = Me.Author_ID
sSQL = "INSERT INTO Tbl_BookAuthor (Book_ID, Author_ID) SELECT " &
Forms!Frm_LibraryDataEdit.txtBookID & " AS Expr1," & intNewAuthorID & " AS
Expr2"
Set db = CurrentDb()
db.Execute sSQL, dbFailOnError
If db.RecordsAffected <> 1 Then
MsgBox "This is not a valid Book ID. Please try again.", _
vbOKOnly + vbInformation, "W. Ross Macdonald School"
Me.Undo
End If
Set db = Nothing
Forms!Frm_LibraryDataEdit!Frm_EditAuthorSubform.Form.Requery
Forms!Frm_LibraryDataEdit!Frm_EditAuthorSubform.Form!cboAuthor = Null
DoCmd.Close
End Sub
I am working using the NotInList event of a combobox to pop up a dialogue
form. I use the popup form to add records to the table upon which the
combobox is based. On the popup form I have two command buttons:
"Undo/Close" and "Insert/Close". Code is reproduced below. This has been
working for me, however, I have discovered a problem: if the user has
actually entered all the appropriate data and then chooses neither of these
command buttons, but instead clicks the control box "X", (and no, I never
thought to try this myself! <g>), the data is inserted into the table. This
isn't what I want, since, to me at least, "X"ing out of the window would
logically mean "discard the data". Is there any way to deal with this
besides disabling the control box? I'd like to avoid changing the standard
windows UI...
Thanks!
Fred Boer
P.S. (For you ADH owners...) I am looking in the Access Developers Handbook
(2002), and I see a section on "Creating Pop-up Forms" in Chapter 8. Is this
a better approach? I must confess that I find the ADH a *wee* bit cryptic;
but I'm willing to give it a go if it is a better solution...
Code to open popup form:
Dim mbrResponse As VbMsgBoxResult
Dim strMsg As String
Dim db As Database, sSQL As String
strMsg = NewData & " isn't an existing author. " & "Add a new author?"
mbrResponse = MsgBox(strMsg, vbYesNo + vbQuestion, "Invalid Author")
Select Case mbrResponse
Case vbYes
DoCmd.OpenForm "Frm_InsertAuthor", _
DataMode:=acFormAdd, _
WindowMode:=acDialog
If ISLOADED("Frm_InsertAuthor") Then
Response = acDataErrAdded
DoCmd.Close acForm, "Frm_InsertAuthor"
Else
Response = acDataErrContinue
End If
Me.cboAuthor.Requery
Case vbNo
Response = acDataErrContinue
End Select
End Sub
Undo/Close:
Private Sub cmdUndo_Click()
Me.Undo
DoCmd.Close
End Sub
Insert/Close:
Dim db As Database, sSQL As String
Dim intNewAuthorID As Integer
If Me.Dirty = True Then Me.Dirty = False
intNewAuthorID = Me.Author_ID
sSQL = "INSERT INTO Tbl_BookAuthor (Book_ID, Author_ID) SELECT " &
Forms!Frm_LibraryDataEdit.txtBookID & " AS Expr1," & intNewAuthorID & " AS
Expr2"
Set db = CurrentDb()
db.Execute sSQL, dbFailOnError
If db.RecordsAffected <> 1 Then
MsgBox "This is not a valid Book ID. Please try again.", _
vbOKOnly + vbInformation, "W. Ross Macdonald School"
Me.Undo
End If
Set db = Nothing
Forms!Frm_LibraryDataEdit!Frm_EditAuthorSubform.Form.Requery
Forms!Frm_LibraryDataEdit!Frm_EditAuthorSubform.Form!cboAuthor = Null
DoCmd.Close
End Sub