On Jun 14, 9:01 am, Mel <MLights...@gma il.comwrote:
Anyone know how I would retrieve the MaxLength property of a column in
my Access Database table? I know how to retrieve table data, for
example the "Quote #" field in my example code below, but I have never
attempted to access a property of a field.
'Beginning of my Code Example
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\suppo rt\webbmq.mdb;"
Dim strSel As String = "SELECT * FROM [Quotes] "
Dim conWebOrdNum As New System.Data.Ole Db.OleDbConnect ion(strConn)
Dim Rec As System.Data.Ole Db.OleDbDataRea der
Dim cmdRead As New System.Data.Ole Db.OleDbCommand (strSel,
conWebOrdNum)
conWebOrdNum.Op en()
Rec = cmdRead.Execute Reader()
Rec.Read()
Session("OrdNum ") = Rec("Quote #")
Rec.Close()
'End of my Code Example
Nevermind, I figured it out. Here is the code I ended up with.
'Beginning of my Code Example
Dim strConn As String = "Provider=Micro soft.JET.OLEDB. 4.0;Data Source
=" & "c:\support\web bmq.mdb"
Dim strRecQuotes As String = "SELECT * FROM [Quotes];"
Dim conQuotes As New System.Data.Ole Db.OleDbConnect ion(strConn)
Dim recQuotes As System.Data.Ole Db.OleDbDataRea der
Dim comQuotes As New System.Data.Ole Db.OleDbCommand (strRecQuotes,
conQuotes)
Dim dt As System.Data.Dat aTable
conQuotes.Open( )
recQuotes = comQuotes.Execu teReader()
recQuotes.Read( )
dt = recQuotes.GetSc hemaTable()
'SET THE TEXT BOX MAXLENGTH PROPERTIES TO THE COLUMN LENGTHS DEFINED
IN THE DATABASE
For i = 0 To dt.Rows.Count - 1
If UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "CUSTOMER" Then
txtCustomer.Max Length = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "PROJECT NAME"
Then
txtProjName.Max Length = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "SHIP TO ADDRESS
1" Then
txtProjAddr1.Ma xLength = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "SHIP TO ADDRESS
2" Then
txtProjAddr2.Ma xLength = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "SHIP TO CITY"
Then
txtProjCity.Max Length = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "SHIP TO ZIPCODE"
Then
txtZip.MaxLengt h = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "CUSCONTACT " Then
txtCusContact.M axLength = dt.Rows(i)("Col umnSize")
ElseIf UCase(Trim(dt.R ows(i)("ColumnN ame"))) = "CUSPHONE" Then
txtCusPhone.Max Length = dt.Rows(i)("Col umnSize")
End If
Next
recQuotes.Close ()
If Not comQuotes Is Nothing Then
comQuotes.Dispo se()
End If
If Not recQuotes Is Nothing Then
recQuotes.Close ()
End If
'End of my Code Example