not_in_List failure

  • Thread starter atlantis43 via AccessMonster.com
  • Start date
A

atlantis43 via AccessMonster.com

Having a problem that I hope someone can help me solve.I’m using a pop-up
dialogue form to gather data to be added as part of the not_in_list event for
a CBO. I’m using a virtually identical structure for several other cbo’s on
the same form which works fine for all other cbo’s, but this one seems to be
giving me an error, and I get NO entry in the cbo when my popup form is
closed. What is more, the saverecord event doesn’t seem to work at all, as I
find no new entry in the underlying table for the data!
Anyone have any idea as to what might be wrong?


The following is the on_close event used on dialogue form for entering
information to be added to main form (“Finsurance infoâ€)::
Private Sub Form_Close()
RunCommand acCmdSaveRecord
If CurrentProject.AllForms("FInsuranceInfo").IsLoaded Then
Forms![FInsuranceinfo]![CoPolicyType].SetFocus
'Stop
Forms![FInsuranceinfo]![CoPolicyType] = Me![InsIndex#]
Forms![FInsuranceinfo]![CoPolicyType].Requery

End If

DoCmd.Restore
End Sub

The following several events occur on CBOâ€copolicytype†field on form
“FInsuranceInfoâ€:

Private Sub CoPolicyType_AfterUpdate()
Me![CoPolicyType].Requery
End Sub

Private Sub CoPolicyType_Exit(Cancel As Integer)

If IsNull(Me![CoPolicyType]) Then
DoCmd.CancelEvent
Me![CoPolicyType].SetFocus
'Else: Me![CoPolicyType].Width = 1600
End If

End Sub

Private Sub CoPolicyType_GotFocus()
'MUST INCLUDE METHOD FOR ADDING NEW POLICY TYPE

Dim DB As DAO.Database, rst As DAO.Recordset, MySQL As String
Set DB = CurrentDb()
Me![CoPolicyType].Width = 3500

Me![CoPolicyType].Requery
MySQL = "SELECT DISTINCTROW Insurpolicy.* FROM Insurpolicy "
MySQL = MySQL & "WHERE (Insurpolicy.[Insco#] = " & Me![SelectCoinsco] & ");"

Set rst = DB.OpenRecordset(MySQL, DB_OPEN_DYNASET)
If rst.RecordCount = 0 Then
Exit Sub 'CRITICAL
'SendKeys "{F4}"
'OR MAYBE OPEN FORM TO ADD
Else: rst.MoveLast
If rst.RecordCount = 1 Then
Me![CoPolicyType] = Me![CoPolicyType].ItemData(0)

ElseIf rst.RecordCount > 1 Then
SendKeys "{F4}"
End If
End If

End Sub

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

' Add a new policy type by typing a name in
' Policy Type combo box.
'If Not IsNull(Me![CoPolicyType]) Then
Dim NewPolicyType As Integer, TruncateName As Integer, Title As String,
MsgDialog As Integer
Const MB_OK = 0
Const MB_YESNO = 4
Const MB_ICONQUESTIONMARK = 32
Const MB_ICONEXCLAMATION = 64
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7
' Display message box asking if user wants to add a
' new insurer.
Title = "Policy Type Not In List"
MsgDialog = MB_YESNO + MB_ICONQUESTIONMARK + MB_DEFBUTTON1
NewPolicyType = MsgBox("Do you want to add a new Policy Type?", MsgDialog,
Title)
If NewPolicyType = IDYES Then
' Remove new name from PolicyType combo box so
' control can be requeried when user returns to form.
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_UNDOFIELD, ,
A_MENU_VER20

' Display message box and adjust length of value entered in
' PolicyType combo box.
Title = "Name Too Long"
MsgDialog = MB_OK + MB_ICONEXCLAMATION
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_UNDOFIELD, , A_MENU_VER20
If Len(NewData) > 25 Then
TruncateName = MsgBox("CoPolicy names can be no longer than 25
characters. The name you entered will be truncated.", MsgDialog, Title)
NewData = Left$(NewData, 25)
End If
' Open Add Policy form.
DoCmd.OpenForm FormName:="FPolicyTypeCo", DataMode:=acAdd, WindowMode:
=acDialog, openargs:=NewData
End If
' Continue without displaying default error message.

Response = acDataErrContinue
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top