Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Default Value using ADO

Status
Not open for further replies.

miromike

Programmer
Feb 6, 2002
4
US
The following is a textbook exercise that I can not get to work. Working in Access 2000, split databases App = Swimreg; Data = Swimdata. I want to change the default value in the swimdata.tblClasses.Semester field to equal the Value in the txtSemesterID textbox.

Any ideas on why this doesn't work? (it actually removes the data in the default property but does not replace it.)
TIA,
Mike

Private Sub txtSemesterID_AfterUpdate()
'Update the default value of the Semester field
'in tblClasses
Dim cnnSwimData As ADODB.Connection
Dim tbl As ADOX.Table
Dim cat As New ADOX.Catalog
Set cnnSwimData = New ADODB.Connection
cnnSwimData.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Ch05\SwimData.mdb;"
Set cat.ActiveConnection = cnnSwimData
Set tbl = cat.Tables("tblClasses")
tbl.Columns("Semester").Properties("Default") = _
Chr(34) & Me![txtSemesterID] & Chr(34)
cnnSwimData.Close
End Sub
 
Replace that line:

tbl.Columns("Semester").Properties("Default") = _
Chr(34) & Me![txtSemesterID] & Chr(34)

with:

tbl.Fields("Semester").DefaultValue = Chr(34) & Me![txtSemesterID] & Chr(34)
Jean-Paul
Montreal
mtljp2@sympatico.ca
 
Hi,

Thanks for your input, but I now get the error message: Compile Error: Method or Data Member not Found.

I'm stumped

Thanks
 
Sorry, in ADO there is no defaultValue, Change it in DAO, it will work;

Jean-Paul
Montreal
mtljp2@sympatico.ca
 
Hey JP,

I just noticed in MS Knowledge Base some problems with ADO 2.5 that may relate to the problem I'm having. So I'm going to concentrate on getting a fix or going back to 2.1 ADO.
Thanks again for your response.

Later
Mike
 
If anyone else is having this problem Check out this article
Code:
[URL unfurl="true"]http://support.microsoft.com/default.aspx?scid=kb;enus;Q255997[/URL]

Later
Mike
 
Put a .Value after the ("Default")

The latest library should be 2.6



tbl.Columns("Semester").Properties("Default").Value = _
Chr(34) & Me![txtSemesterID] & Chr(34)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top