knowledge76
Registered User.
- Local time
- Today, 17:13
- Joined
- Jan 20, 2005
- Messages
- 165
Hello friends,
I am trying to scan the fields of a table with the following code. This should normally give me the maximum length value for each field in the table. However max is not working in vba code as it normally works on table/query level. I therefore used DMAX but it is not working. Any idea how to used the MAX functionality in VBA??
Thanks for your suggestions.
I am trying to scan the fields of a table with the following code. This should normally give me the maximum length value for each field in the table. However max is not working in vba code as it normally works on table/query level. I therefore used DMAX but it is not working. Any idea how to used the MAX functionality in VBA??
Thanks for your suggestions.
PHP:
Option Compare Database
Sub FieldsAnalysis()
On Error GoTo maxlength_error
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Set db = CurrentDb
strobjectname = InputBox("Enter name of table or query to analyse the fields", "Fields Analysis")
Set rs = db.OpenRecordset(strobjectname, dbOpenDynaset)
Debug.Print "Field Name " & "Maximum Length"
Debug.Print "------------------------------"
Do Until rs.EOF
For i = 0 To rs.Fields.Count
Debug.Print rs.Fields(i).Name; "------->" & DMax(Len(rs.Fields(i).Name), strobjectname)
Debug.Print rs.Fields(i)
Next i
Loop
maxlength_error:
Exit Sub
End Sub