Comparing data in diff fields 
Author Message
 Comparing data in diff fields

I'm struggling with a poorly designed table of my own
creation, but it's too late to change the design as it has
already been distributed to other offices where the data
collection is performed.  I have a table with several
fields containing serial numbers.  I need to select the
smallest serial number for each record and copy that value
to yet another field, via VBA or an update query.

Any thoughts?



Wed, 21 Apr 2004 03:15:42 GMT  
 Comparing data in diff fields
In Generals Section:

'user defined type
Public Type tVal
  recID as Long
  recVal as Integer  '(or whatever your data type is)
end Type

'Array of defined type
Public arVal() as tVal

Public Sub FindSmallestValue()
  Dim rsRec as ADODB.Recordset
  Dim iIDX as Integer
  Dim iVal as Integer

  'open your table as a recordset
  Set rsRec = New ADODB.Recordset
  rsRec.Open "SELECT * FROM myTable" , MyConnection
  'scan records to determin smallest value for each
  If Not rsRec.EOF Then
    iIDX = 1
    Do Untill rsRec.EOF
      iVal = rsRec!Field_1
      If rsRec!Field_2 < iVal Then iVal = rsRec!Field_2
      If rsRec!Field_3 < iVal Then iVal = rsRec!Field_3
      ReDim Preserve arVal(iIDX)
      arVal(iIDX).recID = rsRec!Field_ID
      arVal(iIDX).recVal = iVal
      iIDX = iIDX + 1
      rsRec.MoveNext
    Loop
  End If

  Set rsRec = Nothing

  'update Field_4 based on results in array
  For iIDX=1 to Ubound(arVal)

    MyConnection.Execute "UPDATE MyTable SET Field_4=" &  
arVal(iIDX).recVal & " WHERE Field_ID=" & arValiIDX).recID

  Next

End Sub

Quote:
>-----Original Message-----
>I'm struggling with a poorly designed table of my own
>creation, but it's too late to change the design as it
has
>already been distributed to other offices where the data
>collection is performed.  I have a table with several
>fields containing serial numbers.  I need to select the
>smallest serial number for each record and copy that
value
>to yet another field, via VBA or an update query.

>Any thoughts?



Wed, 21 Apr 2004 04:54:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Comparing files (diff)

2. comparing data in specific fields from two tables ???

3. Comparing two data fields in Access through Visual Basic

4. How to Compare Tables, Fields, & Field Properties

5. ADODB Connection String- Two Diff Examples - Two Diff Errors

6. TextBoxes DataControl bound writing to diff field than reading

7. Comparing user entered data to listbox data??

8. comparing MSChart populated data with original data in variant form

9. Passing same data to 2 diff places using bookmarks

10. Join diff connections (SQL Server and ODBC) in Data Environment

11. HELP : get data from 2 diff server

12. Comparing fields from 2 Tables

 

 
Powered by phpBB® Forum Software