Help With Code Syntax

Yes, I added the new declaration statment you posted. And I added my table name here,

Code:
Select Case GetFieldType("YourTableNameHere", Me.cboFields)
 
Sorry to do this, but what do you currently have for code for the function and then what is the full code where you are using it?
 
No problem SOS!

Code:
Option Compare Database
Function ReturnCon(num As Integer) As String
    Select Case num
    Case 1
        ReturnCon = "YesNo"
    Case 2
        ReturnCon = "Byte"
    Case 3
        ReturnCon = "Integer"
    Case 4
        ReturnCon = "Long Integer"
    Case 5
        ReturnCon = "Currency"
    Case 6
        ReturnCon = "Single"
    Case 7
        ReturnCon = "Double"
    Case 8
        ReturnCon = "DateTime"
    Case 9
        ReturnCon = "Unknown"
    Case 10
           ReturnCon = "Text"
    Case 11
            ReturnCon = "OLE Object"
    Case 12
            ReturnCon = "Memo"
    Case 20
            ReturnCon = "Decimal"
    Case Else
        ReturnCon = "Unknown"
End Select
End Function

Function GetFieldType(strTDF As String, strField As String) As String
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
        Set tdf = db.TableDefs(strTDF)
    
        Set fld = tdf.Fields(strField)
        GetFieldType = ReturnCon(fld.Type)

Set fld = Nothing
Set tdf = Nothing
End Function

And the below is in a module called basTableInfo. My table name is
"Ratio Table". I have a space between the two words - I know this is bad naming convention but I will change it later.

Code:
Private Sub cboFields_AfterUpdate()
Dim strFilter As String

Select Case GetFieldType("RATIO_TABLE", Me.cboFields)
Case "Text", "Memo"
   strFilter = "[" & Me.cboFields & "]=" & Chr(34) & Me(Me.cboFields).Value & Chr(34)
Case "DateTime"
   strFilter = "[" & Me.cboFields & "]=#" & Me(Me.cboFields).Value & "#"
Case "Byte", "Integer', "Long Integer", "Currency", "Single", "Double", "Decimal", "YesNo"
   strFilter = "[" & Me.cboFields & "]=" & Me(Me.cboFields).Value 
End Select

Me.Filter = strFilter
Me.FilterOn = True

End Sub
 
You don't put an underscore in - just leave the space:


Select Case GetFieldType("RATIO TABLE", Me.cboFields)
 
Hi SOS - I fixed that - but still the same error. If I step through the code, it trips up before it gets to the sub . . it stops in the function . .
 
Not sure why. I would have to see the database at this point to figure it out I think.
 
Doesn’t look like db has been set.
 
Hi ChrisO and SOS - what would I set the db equal to? Thank you!
 
Assuming everything else is okay then: -

Set db = CurrentDb()
 
ChrisO - well done sir - it works perfectly now. Thank you Bob, SOS and Chris for all your help and patience!!
 

Users who are viewing this thread

Back
Top Bottom