Link to home
Start Free TrialLog in
Avatar of loco337
loco337

asked on

verify record size in database using RDO

I am getting the record size using rdo in the following way..

intFieldSize = rdoConnect.rdoTables(tblName).rdoColumns.Item(i).Size

I am passing the size value to the function below to ensure that the element I want to insert into the database does not exceed the record size. However, many records are being prompted that they are too big, but they are still being inserted into the database? Am I doing something wrong? Is there a better way of doing this?

Thanks..

Public Function cmdTrimLength(strString As Variant, intSize As Long, intType As Integer) As String
Dim intTestStringLen As Integer
Dim intInteger As Integer

Trim (strString)

Select Case intType

Case intType = -6 Or intType = -2

   intInteger = CInt(strString)
   If Len(intInteger) > 1 Then
      strString = Left$(strString, 1) '  SubString does not exceed recordLength
      MsgBox "Field length too large!", vbCritical
   End If
   
Case Else

   If Len(strString) - 2 > intSize Then
      strString = Left$(strString, intSize)
      MsgBox "RECORD LENGTH WAS TOO BIG!", vbCritical
   End If
   
End Select
   cmdTrimLength = strString
End Function
Avatar of CD-Softy
CD-Softy

try changing this line...

intInteger = CInt(strString)

 to...

intInteger = CInt(Len(strString))

I'm not sure what you're trying to achieve, but from your line of code here it seems you're trying to convert a variant to an integer, but that variant might well be a string, which will give you a 0 value.

CD
Avatar of loco337

ASKER

When I get the size from RDO, is that giving me the bit size or the number of characters?
SOLUTION
Avatar of CD-Softy
CD-Softy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loco337

ASKER

Ok.. that was my problem then.
I have to make sure my string does not exceed these datatypes and lengths:

VarChar - i already took care of
Smallint 2
int 4
dateTime 8
tinyint 1
bit 1

How do I take care of dateTime?

Do you think this might work inside my function for bit?

Select Case intType

Case -2

     If intLength > 1 Then
        If strString = "'NULL'" Then
           strString = Replace(strString, "'NULL'", "0")
           strString = Trim(strString)
           intInteger = CInt(strString)
       Else
          strString = Left$(strString, intSize - 1) & "'"
       End If
     End If


'Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial