VB6 database Help Required

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2009
Posts: 15
Reputation: pankaj.garg is an unknown quantity at this point 
Solved Threads: 0
pankaj.garg pankaj.garg is offline Offline
Newbie Poster

VB6 database Help Required

 
0
  #1
27 Days Ago
how can i create an database dynamically i.e. my code creating database while running taking an user input??

i have seen code like below working

Dim db As Database
Dim ReS As Recordset
Set db = OpenDatabase(App.Path + "\Data\" + Userinput + "\Memo.dat")
Set ReS = db.OpenRecordset("Memo")
ReS.AddNew
ReS("Title") = txtTitle.Text
ReS("Details") = txtDescription.Text


but if i do the same, i get an error - "invalid path"
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 835
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 152
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark
 
0
  #2
27 Days Ago
Well first off you need to make sure the directory exists by using the dir function and if it does not exist then you need to use the mkdir statement. HOWEVER, if you are on vista or win7 and in the program files directory, you will not be able to use app.path. Instead, use environ("appdata") & "\ProgramName\Data\nameofmdb.mdb.



Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 472
Reputation: abu taher is an unknown quantity at this point 
Solved Threads: 24
abu taher's Avatar
abu taher abu taher is offline Offline
Posting Pro in Training
 
0
  #3
27 Days Ago
if the file in same folder
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. (App.Path & "\db1.mdb")
I like sword. Attack or Defense.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 15
Reputation: pankaj.garg is an unknown quantity at this point 
Solved Threads: 0
pankaj.garg pankaj.garg is offline Offline
Newbie Poster
 
0
  #4
25 Days Ago
[QUOTE=vb5prgrmr;1041168]Well first off you need to make sure the directory exists by using the dir function and if it does not exist then you need to use the mkdir statement. HOWEVER, if you are on vista or win7 and in the program files directory, you will not be able to use app.path. Instead, use environ("appdata") & "\ProgramName\Data\nameofmdb.mdb.



Good Luck[/QUO

i am on XP...even after i have made the directory...i am not able to create the desired file....do i need to enable any library files or something??
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 835
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 152
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark
 
1
  #5
25 Days Ago
Don't think so but look at Project>References. You should have these four at the top and in this order...

Visual Basic For Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures
OLE Automation

Okay, so you are wanting to create an access database and not just open one (as what your code is saying...)

Okay, see post #12 in this thread for an example... http://www.codeguru.com/forum/showthread.php?t=476345

or since you are using DAO start a new project and add the 2.5/3.51 compatability library and then type in...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim DB As DAO.Database
  2. Set DB = DBEngine.CreateDatabase
and with the cursor somewhere in or at the end of createdatabase press F1 to bring up help.



Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz
 
0
  #6
24 Days Ago
weel theres a function to let the user select a directory, used it to where you save you database to be created. you can also use that to open the database. I think the control is Dialog, opendialog and savedialog box, thats it.

why do you want to create the db during runtime?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz
 
0
  #7
24 Days Ago
why not make function that will open another program which will create a database?
Reply With Quote Quick reply to this message  
Reply

Tags
database, vb

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC