home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database Designers / Erwin 3.0 / DISK15 / DATA.15 / Support / ERWIN30.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-01-04  |  17.6 KB  |  737 lines

  1. Option Explicit
  2.  
  3. Type TranslateItem
  4.     Item As Variant ' index into control or field array
  5.     Value As Variant
  6. End Type
  7.  
  8. Type ListItem
  9.     DisplayVal As String
  10.     DataVal As String
  11. End Type
  12.  
  13. Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  14. Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
  15.  
  16. Function er_ActionNeedsUpdate (Action As Integer)
  17.     Select Case Action
  18.     Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST
  19.         er_ActionNeedsUpdate = True
  20.     Case DATA_ACTIONADDNEW, DATA_ACTIONDELETE
  21.         er_ActionNeedsUpdate = True
  22.     Case DATA_ACTIONCLOSE, DATA_ACTIONUNLOAD
  23.         er_ActionNeedsUpdate = True
  24.     Case DATA_ACTIONBOOKMARK
  25.         er_ActionNeedsUpdate = True
  26.     Case Else
  27.         er_ActionNeedsUpdate = False
  28.     End Select
  29. End Function
  30.  
  31. Function er_CB_ControlValue (cb As Control, fld As Field) As Variant
  32.     er_CB_ControlValue = er_CB_ControlXlateValue(cb, fld, "Y", "N")
  33.  
  34. End Function
  35.  
  36. Function er_CB_ControlXlateValue (cb As Control, fld As Field, sOn As String, sOff As String) As Variant
  37.     Dim nValue As Integer
  38.     Dim sValue As String
  39.     Dim sMsg As String
  40.     Dim nOff As Integer
  41.     Dim nOn As Integer
  42.  
  43.  
  44.     Select Case Abs(cb.Value)
  45.     Case 0
  46.     sValue = sOff
  47.     nValue = Val(sOff)
  48.     Case 1
  49.     sValue = sOn
  50.     nValue = Val(sOn)
  51.     Case Else
  52.         sValue = ""
  53.     End Select
  54.  
  55.     Select Case True
  56.     Case er_FieldIsNumeric(fld)
  57.     er_CB_ControlXlateValue = nValue
  58.     Case er_FieldIsString(fld)
  59.         er_CB_ControlXlateValue = sValue
  60.     Case Else
  61.         Beep
  62.         sMsg = fld.Name & " uses a data type that is not supported by ERwin's code translation feature."
  63.         MsgBox sMsg, MB_OK + MB_ICONEXCLAMATION, "ERwin for Visual Basic"
  64.     End Select
  65.  
  66. End Function
  67.  
  68. Function er_CB_FieldValue (cb As Control, fld As Field) As Integer
  69.     er_CB_FieldValue = er_CB_FieldXlateValue(cb, fld, "Y", "N")
  70.  
  71. End Function
  72.  
  73. Function er_CB_FieldXlateValue (cb As Control, fld As Field, sOn As String, sOff As String) As Integer
  74.     Dim sMsg As String
  75.     Dim sBuff As String
  76.  
  77.  
  78.     If IsNull(fld) Then
  79.     er_CB_FieldXlateValue = 2
  80.     Else
  81.     Select Case True
  82.     Case er_FieldIsNumeric(fld)
  83.         If fld = Val(sOff) Then
  84.         er_CB_FieldXlateValue = 0
  85.         ElseIf fld = Val(sOn) Then
  86.         er_CB_FieldXlateValue = 1
  87.         Else
  88.         er_CB_FieldXlateValue = 2
  89.         End If
  90.     Case er_FieldIsString(fld)
  91.         sBuff = fld
  92.         sBuff = Trim(sBuff)
  93.  
  94.         If sBuff = sOff Then
  95.         er_CB_FieldXlateValue = 0
  96.         ElseIf sBuff = sOn Then
  97.         er_CB_FieldXlateValue = 1
  98.         Else
  99.         er_CB_FieldXlateValue = 2
  100.         End If
  101.     Case Else
  102.         Beep
  103.         sMsg = fld.Name & " uses a data type that is not supported by ERwin's code translation feature."
  104.         MsgBox sMsg, MB_OK + MB_ICONEXCLAMATION, "ERwin for Visual Basic"
  105.     End Select
  106.     End If
  107.  
  108. End Function
  109.  
  110. Sub er_ClearChangedFlags (axCtrl() As Control, abFlag() As Integer)
  111.     Dim iMax As Integer
  112.     Dim i As Integer
  113.  
  114.     iMax = UBound(axCtrl)
  115.  
  116.     For i = 0 To iMax - 1
  117.     axCtrl(i).DataChanged = False
  118.     abFlag(i) = False
  119.     Next i
  120.  
  121. End Sub
  122.  
  123. Function er_CurrRowExists (ds As Data)
  124.     Dim sBookMark As String
  125.     Dim vValue As Variant
  126.  
  127.     On Error GoTo CurrRowExists_Handler
  128.     er_CurrRowExists = True
  129.  
  130.     ' Try to cause the "no current record" error
  131.     'sBookMark = ds.Recordset.Bookmark
  132.     vValue = ds.Recordset.Fields(0)
  133.  
  134.     If ds.EditMode = dbEditAdd Then
  135.     er_CurrRowExists = False
  136.     End If
  137.  
  138.     Exit Function
  139.  
  140. CurrRowExists_Handler:
  141.     Select Case Err
  142.     Case 3021   ' Error: No current record
  143.         er_CurrRowExists = False
  144.         Resume Next
  145.     Case 91     ' Object variable not set
  146.         er_CurrRowExists = False
  147.         Resume Next
  148.     Case Else
  149.         er_DisplayError (Err)
  150.         Resume Next
  151.     End Select
  152.  
  153. End Function
  154.  
  155. Sub er_DeleteButton (ds As Data)
  156.     If ds.EditMode <> dbEditAdd Then
  157.         er_ffDeleteRow ds
  158.     Else
  159.     'bNoSave = True
  160.     MoveFromCurrRow ds
  161.     'bNoSave = False
  162.     End If
  163.  
  164. End Sub
  165.  
  166. Sub er_DisplayError (ErrNum As Integer)
  167.     Beep
  168.     MsgBox "Error:" & Str(ErrNum) & " - " & Error(ErrNum)
  169.  
  170. End Sub
  171.  
  172. Function er_DS_FieldsAvailable (ds As Data)
  173.     er_DS_FieldsAvailable = er_CurrRowExists(ds) Or ds.EditMode <> DATA_EDITNONE
  174. End Function
  175.  
  176. Sub er_DS_Update (Frm As Form, ds As Data, nNoRepos As Integer, bUpdateFailed As Integer)
  177.     Dim bNew As Integer
  178.     Dim bUpdating As Integer
  179.  
  180.     On Error GoTo DS_Update_Handler
  181.  
  182.     bUpdateFailed = False   'MAR
  183.  
  184.     If er_CurrRowExists(ds) = False Then
  185.         bNew = True
  186.     End If
  187.  
  188. '    If er_CurrRowExists(ds) Or ds.EditMode = dbEditAdd Then
  189.     If ds.EditMode <> DATA_EDITNONE Then
  190.     nNoRepos = nNoRepos + 1
  191.     bUpdating = True
  192.     ds.Recordset.Update
  193.     bUpdating = False
  194.     nNoRepos = nNoRepos - 1
  195.  
  196.     If bNew And Not bUpdateFailed And ds.Recordset.RecordCount Then
  197.         ds.Recordset.MoveLast
  198.         bNew = False
  199.         End If
  200.     End If
  201.  
  202.     Exit Sub
  203.  
  204. DS_Update_Handler:
  205.     Select Case Err
  206.     Case 3020   ' Error: Update without Add New or Edit
  207.         Resume Next
  208.  
  209.         Case 3021   ' Error: No current record
  210.             Resume Next
  211.  
  212.         Case Else
  213.             er_DisplayError (Err)
  214.         If bUpdating Then bUpdateFailed = True  'MAR
  215.             Resume Next
  216.     End Select
  217.  
  218.  
  219. End Sub
  220.  
  221. Function er_ErrorPrompt (ErrNum As Integer, sQuestion As String, nButtons As Integer, sTitle As String)
  222.     Dim sMsg As String
  223.  
  224.     If sQuestion = "" Then
  225.     sQuestion = "Do you wish to retry the operation?"
  226.     nButtons = vbYesNo Or vbExclamation
  227.     End If
  228.  
  229.     If sTitle = "" Then
  230.     sTitle = "Application Error"
  231.     End If
  232.  
  233.     Beep
  234.     sMsg = "Error:" & Str(ErrNum) & " - " & Error(ErrNum)
  235.     sMsg = sMsg + String(2, Chr(13)) & sQuestion
  236.     er_ErrorPrompt = MsgBox(sMsg, nButtons, sTitle)
  237.  
  238. End Function
  239.  
  240. Sub er_ffDeleteRow (ds As Data)
  241.     If ds.Recordset.RecordCount = 0 Then Exit Sub
  242.  
  243.     On Error GoTo ErrorHandler
  244.     ds.Recordset.Delete
  245.     If Not er_CurrRowExists(ds) Then    'MAR, may not work in VB3
  246.     MoveFromCurrRow ds
  247.     End If
  248.     If ds.Recordset.RecordCount = 0 Then
  249.     'ds.Recordset.AddNew    'MAR replaced by next line
  250.     ds.Refresh
  251.     End If
  252.  
  253. er_ffDeleteRow_Done:
  254.     Exit Sub
  255.  
  256. ErrorHandler:
  257.  
  258.     Select Case Err
  259.     'Case 3197   ' Error: Data has changed, operation stopped
  260.     '    ds.Recordset.Update
  261.     '    Resume
  262.  
  263.     Case 3021   ' Error: No current record
  264.         Resume Next
  265.  
  266.     Case 444    ' Method not applicable in this context
  267.         Resume Next
  268.  
  269.     Case Else
  270.         er_DisplayError (Err)
  271.         Resume er_ffDeleteRow_Done
  272.     End Select
  273.  
  274. End Sub
  275.  
  276. Function er_FieldIsNumeric (fld As Field) As Integer
  277.     Select Case fld.Type
  278.     Case DB_BOOLEAN
  279.         er_FieldIsNumeric = True
  280.     Case DB_BYTE
  281.         er_FieldIsNumeric = True
  282.     Case DB_INTEGER
  283.         er_FieldIsNumeric = True
  284.     Case DB_LONG
  285.         er_FieldIsNumeric = True
  286.     Case DB_CURRENCY
  287.         er_FieldIsNumeric = True
  288.     Case DB_SINGLE
  289.         er_FieldIsNumeric = True
  290.     Case DB_DOUBLE
  291.         er_FieldIsNumeric = True
  292.     Case Else
  293.         er_FieldIsNumeric = False
  294.     End Select
  295.  
  296. End Function
  297.  
  298. Function er_FieldIsString (fld As Field) As Integer
  299.     Select Case fld.Type
  300.     Case DB_TEXT
  301.         er_FieldIsString = True
  302.     Case DB_LONGBINARY
  303.         er_FieldIsString = True
  304.     Case DB_MEMO
  305.         er_FieldIsString = True
  306.     Case Else
  307.         er_FieldIsString = False
  308.     End Select
  309.  
  310. End Function
  311.  
  312. ' Translates a display value into a data value using the specified ListItem array
  313. ' sDisplayVal: (Input)The display value to translate
  314. ' axList(): (Input) The ListItem array
  315. ' sDataVal: (Output) The translated value
  316. ' Returns: True if sDisplayVal was found in the list, sDataVal is the translated value.
  317. '          False if sDisplayVal was not found in the list, sDataVal is sDisplayVal.
  318. '==================================================================================
  319. Function er_GetDataValue (sDisplayVal As String, axList() As ListItem, sDataVal As String)
  320.     Dim iMax As Integer
  321.     Dim i As Integer
  322.  
  323.     iMax = UBound(axList)
  324.  
  325.     For i = LBound(axList) To iMax - 1
  326.     If sDisplayVal = axList(i).DisplayVal Then
  327.         sDataVal = axList(i).DataVal
  328.         er_GetDataValue = True
  329.         Exit Function
  330.     End If
  331.     Next i
  332.  
  333.     er_GetDataValue = False
  334.     sDataVal = sDisplayVal
  335.  
  336. End Function
  337.  
  338. ' Translates a data value into a display value using the specified ListItem array
  339. ' sDataVal: (Input)The data value to translate
  340. ' axList(): (Input) The ListItem array
  341. ' sDisplayVal: (Output) The translated value
  342. ' Returns: True if sDataVal was found in the list, sDisplayVal is the translated value.
  343. '          False if sDataVal was not found in the list, sDisplayVal is sDataVal.
  344. '==================================================================================
  345. Function er_GetDisplayValue (sDataVal As String, axList() As ListItem, sDisplayVal As String)
  346.     Dim iMax As Integer
  347.     Dim i As Integer
  348.     Dim sTrimmedString As String
  349.  
  350.     sTrimmedString = Trim(sDataVal)
  351.     iMax = UBound(axList)
  352.  
  353.     For i = LBound(axList) To iMax - 1
  354.     If sTrimmedString = axList(i).DataVal Then
  355.         sDisplayVal = axList(i).DisplayVal
  356.         er_GetDisplayValue = True
  357.         Exit Function
  358.     End If
  359.     Next i
  360.  
  361.     er_GetDisplayValue = False
  362.     sDisplayVal = sTrimmedString
  363.  
  364. End Function
  365.  
  366. Sub er_LoadList (ListCtrl As Control, ListItems() As ListItem)
  367.     Dim i As Integer
  368.  
  369.     For i = 0 To UBound(ListItems) - 1
  370.     ListCtrl.AddItem ListItems(i).DisplayVal
  371.     ListCtrl.ItemData(ListCtrl.NewIndex) = i
  372.     Next
  373. End Sub
  374.  
  375. Sub er_NewButton (Frm As Form, ds As Data, nNoRepos As Integer, bUpdateFailed As Integer)
  376.  
  377.     bUpdateFailed = False   'MAR, MB2
  378.     'If er_CurrRowExists(ds) And ds.EditMode <> dbEditNone Then  'MAR line replaced
  379.     If ds.EditMode <> dbEditNone Then
  380.     er_DS_Update Frm, ds, nNoRepos, bUpdateFailed
  381.     End If
  382.  
  383.     If Not bUpdateFailed Then   'MAR
  384.     ds.Recordset.AddNew
  385.     End If  'MAR
  386.  
  387. End Sub
  388.  
  389. Function er_NullValue (fld As Field) As Variant
  390.     Select Case fld.Type
  391.     Case DB_BOOLEAN
  392.         er_NullValue = 0
  393.     Case DB_BYTE
  394.         er_NullValue = 0
  395.     Case DB_INTEGER
  396.         er_NullValue = 0
  397.     Case DB_LONG
  398.         er_NullValue = 0
  399.     Case DB_CURRENCY
  400.         er_NullValue = 0
  401.     Case DB_SINGLE
  402.         er_NullValue = 0
  403.     Case DB_DOUBLE
  404.         er_NullValue = 0
  405.     Case DB_DATE
  406.         er_NullValue = ""
  407.     Case DB_TEXT
  408.         er_NullValue = ""
  409.     Case DB_LONGBINARY
  410.         er_NullValue = ""
  411.     Case DB_MEMO
  412.         er_NullValue = ""
  413.     End Select
  414.  
  415. End Function
  416.  
  417. Function er_ObjectSet (ds As Data) As Integer
  418.     Dim iMode As Integer
  419.     On Error GoTo ObjectSet_Handler
  420.  
  421.     er_ObjectSet = True
  422.  
  423.     ' Try to cause an error by accessing the data control
  424.     If ds.EditMode = dbEditAdd Then iMode = 0 'no op
  425.  
  426.     Exit Function
  427.  
  428. ObjectSet_Handler:
  429.     Select Case Err
  430.     Case 91
  431.         er_ObjectSet = False
  432.         Resume Next
  433.  
  434.     Case Else
  435.         er_DisplayError (Err)
  436.         Resume Next
  437.     End Select
  438. End Function
  439.  
  440. Function er_PreValidate (ds As Data, Action As Integer, Save As Integer) As Integer
  441.     er_PreValidate = False
  442.  
  443.     Select Case Action
  444.     'Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST, DATA_ACTIONDELETE    'MAR removed
  445.     Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST
  446.         If ds.Recordset.RecordCount = 0 And Save = False Then
  447.         'Action = DATA_ACTIONCANCEL 'MAR removed
  448.             Save = False
  449.             er_PreValidate = True
  450.         End If
  451.  
  452.     Case DATA_ACTIONDELETE
  453.     If ds.Recordset.RecordCount = 0 And Save = False Then
  454.         Action = DATA_ACTIONCANCEL
  455.         Save = False
  456.         er_PreValidate = True
  457.     End If
  458.  
  459.     Case DATA_ACTIONUPDATE
  460.         If Save = False Then
  461.             Action = DATA_ACTIONCANCEL
  462.             er_PreValidate = True
  463.         End If
  464.  
  465.     Case DATA_ACTIONBOOKMARK
  466.         If Save = False Then
  467.         er_PreValidate = True
  468.         End If
  469.     End Select
  470.  
  471.     Exit Function
  472.  
  473. PreVal_Handler:
  474.     Select Case Err
  475.     Case 3021   ' Error: No current record
  476.         Beep
  477.         Resume Next
  478.  
  479.     Case Else
  480.         er_DisplayError (Err)
  481.         Resume Next
  482.     End Select
  483.  
  484. End Function
  485.  
  486. Sub er_RestoreChangedFlags (axCtrl() As Control, abFlag() As Integer)
  487.     Dim iMax As Integer
  488.     Dim i As Integer
  489.  
  490.     iMax = UBound(axCtrl)
  491.  
  492.     For i = 0 To iMax - 1
  493.     axCtrl(i).DataChanged = abFlag(i)
  494.     Next i
  495.  
  496. End Sub
  497.  
  498. Sub er_SaveChangedFlags (axCtrl() As Control, abFlag() As Integer)
  499.     Dim iMax As Integer
  500.     Dim i As Integer
  501.  
  502.     iMax = UBound(axCtrl)
  503.  
  504.     For i = 0 To iMax - 1
  505.     abFlag(i) = axCtrl(i).DataChanged
  506.     Next i
  507.  
  508. End Sub
  509.  
  510. Sub er_SetEditMode (ds As Data)
  511.     On Error GoTo SetEditMode_Handler
  512.  
  513.     If er_CurrRowExists(ds) And ds.EditMode = dbEditNone Then
  514.         ds.Recordset.Edit
  515.     End If
  516.  
  517.     Exit Sub
  518.  
  519. SetEditMode_Handler:
  520.     Select Case Err
  521.     'Case 3197   ' Error: Data has changed, operation stopped
  522.     '    Resume
  523.  
  524.     Case Else
  525.         er_DisplayError (Err)
  526.         Resume Next
  527.     End Select
  528.  
  529. End Sub
  530.  
  531. Sub er_SetFieldToNull (fld As Field)
  532.     Select Case fld.Type
  533.     Case DB_BOOLEAN
  534.         fld = 0
  535.     Case DB_BYTE
  536.         fld = 0
  537.     Case DB_INTEGER
  538.         fld = 0
  539.     Case DB_LONG
  540.         fld = 0
  541.     Case DB_CURRENCY
  542.         fld = 0
  543.     Case DB_SINGLE
  544.             fld = 0
  545.     Case DB_DOUBLE
  546.         fld = 0
  547.     Case DB_DATE
  548.         fld = Date
  549.     Case DB_TEXT
  550.         fld = ""
  551.     Case DB_LONGBINARY
  552.         fld = ""
  553.     Case DB_MEMO
  554.         fld = ""
  555.     End Select
  556.  
  557. End Sub
  558.  
  559. Function er_SQLValue (ds As Data, sFldName As String)
  560.     Dim bQuotes As Integer
  561.     Dim sValue As String
  562.     Dim vValue As Variant
  563.  
  564.     Select Case ds.Recordset(sFldName).Type
  565.     Case DB_TEXT
  566.         bQuotes = True
  567.     Case DB_MEMO
  568.         bQuotes = True
  569.     Case Else
  570.         bQuotes = False
  571.     End Select
  572.  
  573.     If IsNull(ds.Recordset(sFldName)) Then
  574.     vValue = er_NullValue(ds.Recordset(sFldName))
  575.     sValue = vValue
  576.     Else
  577.     sValue = LTrim(RTrim(ds.Recordset(sFldName)))
  578.     End If
  579.  
  580.     If bQuotes Then
  581.         sValue = "'" & sValue & "'"
  582.     End If
  583.  
  584.     er_SQLValue = sValue
  585.  
  586. End Function
  587.  
  588. Function erwAddDisplayFieldTranslation (ctlData As Data, strFieldName As String, varValue As Variant, udtTranslateList() As TranslateItem, nListCount As Integer)
  589.     Dim nTmpListCount As Integer
  590.     Dim nTmpListBound As Integer
  591.     Dim udtTmpTranslateItem As TranslateItem
  592.  
  593.     nTmpListCount = nListCount
  594. '   nTmpListBound = UBound(udtTranslateList)
  595.  
  596. '    If nTmpListBound = nTmpListCount Then
  597. '        ReDim udtTranslateList(nTmpListBound + 20)
  598. '    End If
  599.  
  600.     udtTmpTranslateItem.Item = ctlData.Recordset.Fields(strFieldName).OrdinalPosition
  601.     udtTmpTranslateItem.Value = varValue
  602.     udtTranslateList(nTmpListCount) = udtTmpTranslateItem
  603.  
  604.     erwAddDisplayFieldTranslation = nTmpListCount + 1
  605. End Function
  606.  
  607. Function erwDoDisplayFieldTranslation (ctlData As Data, TranslateList() As TranslateItem, nListCount As Integer)
  608.     Dim i As Integer
  609.     Dim nCount As Integer
  610.  
  611.     For i = 0 To nListCount - 1
  612.     If TranslateList(i).Item >= 0 Then
  613.             ctlData.Recordset.Fields(TranslateList(i).Item) = TranslateList(i).Value
  614.             nCount = nCount + 1
  615.         End If
  616.     Next
  617.     erwDoDisplayFieldTranslation = True
  618. End Function
  619.  
  620. Sub erwGetNewListField (ListCtrl As Control, DataCtrl As Data, FieldName As String, ListItems() As ListItem, bNoClick As Integer)
  621.     Dim GstrCount As Integer
  622.     Dim GStrIndex As Integer
  623.     Dim ListCount As Integer
  624.     Dim i As Integer
  625.     Dim FieldValue As String
  626.     Dim DisplayValue As String
  627.  
  628.     Err = 0
  629.     GStrIndex = -1
  630.     On Error Resume Next
  631.     If IsNull(DataCtrl.Recordset.Fields(FieldName)) Then
  632.     FieldValue = ""
  633.     Else
  634.     FieldValue = Trim(DataCtrl.Recordset.Fields(FieldName))
  635.     End If
  636.     GstrCount = UBound(ListItems)
  637.     For i = 0 To GstrCount - 1
  638.     If ListItems(i).DataVal = FieldValue Then
  639.         GStrIndex = i
  640.         DisplayValue = ListItems(i).DisplayVal
  641.         Exit For
  642.     End If
  643.     Next
  644.  
  645.     If GStrIndex = -1 Then
  646.     bNoClick = True
  647.     ListCtrl.ListIndex = -1
  648.     bNoClick = False
  649.     If TypeOf ListCtrl Is ComboBox Then
  650.         bNoClick = True
  651.         ListCtrl.Text = FieldValue
  652.         bNoClick = False
  653.     End If
  654.     Else
  655. '                ListCtrl.Text = DisplayValue
  656.     ListCount = ListCtrl.ListCount
  657.     For i = 0 To ListCount - 1
  658.         If ListCtrl.ItemData(i) = GStrIndex Then
  659.         bNoClick = True
  660.         ListCtrl.ListIndex = i
  661.         bNoClick = False
  662.         Exit For
  663.        End If
  664.     Next
  665.     End If
  666. End Sub
  667.  
  668. Function erwSetNewListField (ListCtrl As Control, DataCtrl As Data, FieldName As String, ListItems() As ListItem, bValidate As Integer, bNoClick As Integer)
  669.     Dim i As Integer
  670.     Dim ListIndex As Integer
  671.     Dim GStrIndex As Long
  672.     Dim FieldValue As String
  673.     Dim bRetVal
  674.  
  675.     bRetVal = True
  676.     Err = 0
  677.     On Error Resume Next
  678.     ListIndex = ListCtrl.ListIndex
  679.  
  680.     'If no list selection, see if typed in text is on list and select it if so
  681.     If ListIndex = -1 Then
  682.     If TypeOf ListCtrl Is ComboBox Then
  683.         For i = 0 To ListCtrl.ListCount - 1
  684.             If ListCtrl.List(i) = ListCtrl.Text Then
  685.             bNoClick = True
  686.             ListCtrl.ListIndex = i
  687.             bNoClick = False
  688.             Exit For
  689.             End If
  690.         Next
  691.         End If
  692.     End If
  693.  
  694.     'If still no selection, do validation/translation
  695.     ListIndex = ListCtrl.ListIndex
  696.     If ListIndex = -1 Then
  697.     If bValidate Then
  698.         bRetVal = False
  699.     Else
  700.         DataCtrl.Recordset.Fields(FieldName) = ListCtrl.Text
  701.         End If
  702.     Else
  703.         GStrIndex = ListCtrl.ItemData(ListIndex)
  704.         FieldValue = ListItems(GStrIndex).DataVal
  705.         DataCtrl.Recordset.Fields(FieldName) = FieldValue
  706.     End If
  707.  
  708.     erwSetNewListField = bRetVal
  709. End Function
  710.  
  711. Sub MoveFromCurrRow (ds As Data)
  712.     On Error GoTo MoveFrom_Handler
  713.  
  714.     ds.Recordset.MoveNext
  715.     If ds.Recordset.EOF Then
  716.         If ds.Recordset.RecordCount > 0 Then
  717.             ds.Recordset.MovePrevious
  718.     Else
  719.         ds.Recordset.AddNew
  720.     End If
  721.     End If
  722.  
  723.     Exit Sub
  724.  
  725. MoveFrom_Handler:
  726.     Select Case Err
  727.     Case 3021   ' Error: No current record
  728.         Resume Next
  729.  
  730.     Case Else
  731.         er_DisplayError (Err)
  732.         Resume Next
  733.     End Select
  734.  
  735. End Sub
  736.  
  737.