User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 397,859 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,387 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 4506 | Replies: 6
Reply
Join Date: Apr 2007
Posts: 69
Reputation: SCBWV is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
SCBWV SCBWV is offline Offline
Junior Poster in Training

Help VB6 / Access DAO Add Field to Existing Table/Query

  #1  
Nov 23rd, 2007
I have a VB6 application that uses DAO to read and write MS Access files. Since the program uses Access files exclusives, it was written in DAO instead of ADO. The recordsets within the program are based on queries in the database. I need to add a field to the table and query. I'm sure I can figure out testing for the existence of the field in. My question: How can I add a new field to the table AND query?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: atplerry is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
atplerry atplerry is offline Offline
Light Poster

Re: VB6 / Access DAO Add Field to Existing Table/Query

  #2  
Nov 24th, 2007
Pls i also need to know how to use DAO instead of ADO Because i know a bit of ADO Connection and am seeking to know as a fresh user of DAO connect to the Database, You can email some few example if present OR send the site that give tutorial on either online or ebooks pls send the detail to the address below
atplerry@yahoo.com
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 493
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 45
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro in Training

Tutorial Re: VB6 / Access DAO Add Field to Existing Table/Query

  #3  
Nov 24th, 2007
Originally Posted by SCBWV View Post
I have a VB6 application that uses DAO to read and write MS Access files. Since the program uses Access files exclusives, it was written in DAO instead of ADO. The recordsets within the program are based on queries in the database. I need to add a field to the table and query. I'm sure I can figure out testing for the existence of the field in. My question: How can I add a new field to the table AND query?


check this sample code in the attachment.
hope this will be able to give u some idea.

regards
Shouvik
Attached Files
File Type: zip Online Database.zip (2.3 KB, 48 views)
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 493
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 45
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro in Training

Tutorial Re: VB6 / Access DAO Add Field to Existing Table/Query

  #4  
Nov 24th, 2007
Originally Posted by atplerry View Post
Pls i also need to know how to use DAO instead of ADO Because i know a bit of ADO Connection and am seeking to know as a fresh user of DAO connect to the Database, You can email some few example if present OR send the site that give tutorial on either online or ebooks pls send the detail to the address below
atplerry@yahoo.com



check out this sample project.
it was created in DAO technique and it has everything u need to know about connecting the database using DAO object and frequently used database operations.

regards
Shouvik
Attached Files
File Type: zip Employee Manager.zip (62.5 KB, 33 views)
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote  
Join Date: Apr 2007
Posts: 69
Reputation: SCBWV is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
SCBWV SCBWV is offline Offline
Junior Poster in Training

Help Re: VB6 / Access DAO Add Field to Existing Table/Query

  #5  
Nov 24th, 2007
Ok, I figured out how to add a field to an existing table with DAO

Set dbsAccess = DBEngine.Workspaces(0).OpenDatabase(dbFile$, False, False)
'Agencies is a table in the Access database
Set td = dbsAccess.TableDefs("Agencies")
'Address2 is the field to be added
Set fd = td.CreateField("Address2", dbText, 50)
td.Fields.Append fd
dbsAccess.Close

Now the question is, how do I add the new field "Address2" to existing queries in the database? The database contains a query call "Agency Query." I need to add Address2 to this query.

Thanks for any help.
Reply With Quote  
Join Date: Apr 2007
Posts: 69
Reputation: SCBWV is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
SCBWV SCBWV is offline Offline
Junior Poster in Training

Solution Re: VB6 / Access DAO Add Field to Existing Table/Query

  #6  
Nov 25th, 2007
Nevermind... I figured it out. Using SQL of the QueryDefs overwrites the original query in the database with the new one. This thread can be closed.

Set dbsAccess = DBEngine.Workspaces(0).OpenDatabase(dbFile$, False, False)
Set qd = dbsAccess.QueryDefs("Agency Query")
qd.SQL = "SELECT...
dbsAccess.Close
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 493
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 45
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro in Training

News Re: VB6 / Access DAO Add Field to Existing Table/Query

  #7  
Nov 25th, 2007
Originally Posted by SCBWV View Post
Nevermind... I figured it out. Using SQL of the QueryDefs overwrites the original query in the database with the new one. This thread can be closed.

Set dbsAccess = DBEngine.Workspaces(0).OpenDatabase(dbFile$, False, False)
Set qd = dbsAccess.QueryDefs("Agency Query")
qd.SQL = "SELECT...
dbsAccess.Close


if you have benefited from the reply then post a feedback and mark the thread as solved.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 8:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC