Solved

Append field to database during run-time

Posted on 2001-06-20
5
170 Views
Last Modified: 2010-05-02
I am very new to VB and I am trying to append a new field to a database with the name of the field being a string the user enters in (boolean-type field) and I am getting stuck.  I am trying not to use SQL statements or adodb connections because I don't really understand them. I tried:

 MattressType.Recordset.Fields.Append txtHardness.Text

but it gives me a run-time error of "type mismatch" and highlights the "txtHardness.Text" which is a string but I think I'm supposed to have an object there. Please help me as I am very confused (as you can probably tell).
Thanks!
~Sarah
0
Comment
Question by:snaegs99
5 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6211389
Append does not append a field to the database, it allows to build a dynamic recordset.
If you want to change/alter a table you need to use tsql ? for sqlserver or sqlplus for oracle.
0
 
LVL 3

Accepted Solution

by:
jrspano earned 50 total points
ID: 6211455
for sql server 7 and 2000

alter table tablename ADD columnname FLOAT NOT NULL

this adds a column named columnname that has float for type and doesn't accept nulls.
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6211458
you really should learn to understand ado.  there is only so much you can do without them.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6211766
If you want to append a field you must use the TableDef object and append a field object, using ADO and SQL would be much easier and more worth your while to learn for many other reasons.

But here is a sample I used to use with VB3, DAO and Access 2.0

    Dim db as Database
    Dim tb As New TableDef
    ReDim fd(0 To 6) As New Field

    Set db = CreateDatabase(DBName$, DB_LANG_GENERAL)
    tb.Name = "language"

    fd(0).Name = "text"
    fd(0).Type = db_text
    fd(0).Size = 255

    tb.fields.append fd(0)

    db.tabledefs.append tb

hope this helps
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139597
Hi snaegs99@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept jrspano's comment(s) as an answer.

snaegs99@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now