Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 15th, 2005, 03:54 PM
Registered User
 
Join Date: May 2005
Location: glasgow, , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access db/ Common Dialog/ errors in code

I am writing an address book in vb6. My version of VB uses DAO 3.51 - I can't load the upgrade from MS. I have tried running the following with an Access 2000 and 97 file but both give me the following meassage runtime error 3343 unrecognizable database format.

Here is my code, some more questions at the end....

Dim TextFileNum As Integer
Dim OpenFileName As String
Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
OpenFileName = Empty
mnuClose.Enabled = False

End Sub

Private Sub mnuNew_Click()
f = FreeFile
CMDialog1.Filter = "all files|*.*|text|*.txt"
CMDialog1.FilterIndex = 0
CMDialog1.InitDir = App.Path
CMDialog1.ShowOpen
MsgBox "You selected: " + CMDialog1.FileName
Set db = OpenDatabase(CMDialog1.FileName)
Set rs = db.OpenRecordset("Table1")
rs.AddNew
rs![Name] = txtName.Text
rs![Address1] = txtAddress1.Text
rs![Address2] = txtAddress2.Text
rs![Address3] = txtAddress3.Text
rs![Postcode] = txtPostcode.Text
TextFileNum = FreeFile
OpenFileName = CMDialog1.FileName
Open OpenFileName For Output As #f
cmdAdd.Visible = True
mnuNew.Enabled = False
mnuOpen.Enabled = False
mnuClose.Enabled = True

End Sub

Private Sub mnuOpen_Click()

f = FreeFile
'CMDialog1.CancelError = True
'On Error GoTo Errhandler 'set error for cancel button
CMDialog1.Filter = "all files|*.*|text|*.txt"
CMDialog1.FilterIndex = 0
CMDialog1.InitDir = App.Path
CMDialog1.ShowOpen
MsgBox "You selected: " + CMDialog1.FileName
Set db = OpenDatabase(CMDialog1.FileName)
Set rs = db.OpenRecordset("Table1")
rs.Edit
txtName.Text = rs![Name]
txtAddress1.Text = rs![Address1]
txtAddress2.Text = rs![Address2]
txtAddress3.Text = rs![Address3]
txtPostcode.Text = rs![Postcode]
rs.MoveFirst

TextFileNum = FreeFile
OpenFileName = CMDialog1.FileName
Open OpenFileName For Append As #f
cmdAdd.Visible = True
mnuNew.Enabled = False
mnuOpen.Enabled = False
mnuClose.Enabled = True

Exit Sub

'Errhandler:
'MsgBox "You clicked the cancel button"
'Exit Sub

End Sub

Private Sub mnuClose_Click()

'if

cmdAdd.Visible = False

'then

mnuOpen.Enabled = True
mnuNew.Enabled = True
mnuClose.Enabled = False

'Else

MsgBox "001 File not open", vbOKOnly, "Error Details"

End Sub

Private Sub mnuExit_Click()
rs.Close
Close (f)
End
End Sub

Private Sub cmdAdd_Click()
'rs.AddNew
rs![Name] = txtName.Text
rs![Address1] = txtAddress1.Text
rs![Address2] = txtAddress2.Text
rs![Address3] = txtAddress3.Text
rs![Postcode] = txtPostcode.Text
rs.Update

End Sub

It is not finished yet hence the rem statements. I have strict coding guidelines and I am sure there are things in my code that could be streamlined - however most of it is a requirement of the end user.

Also this opens up a db I have previously created in access. Is there an easy way to code so that when I click menu new it creates a new db with the fields name, address1, address2, address3, postcode automatically. Then upon selecting menu open I have a choice of all previously created db's.

I am still struggling to work out the logic behind the coding so I would be really grateful if you could give me an answer in newbie language.

Many thanks

Harry
__________________
A very grateful Scot.
Reply With Quote
  #2 (permalink)  
Old May 25th, 2005, 10:34 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

On what line do you receive the error?

I suspect that you are going to be out of luck trying to open an unrecognizable DB format (if it is due to versioning), but still, it would be good to know where you get the error.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
coding problem in common dialog box cancertropica Visual Basic 2005 Basics 0 July 30th, 2008 09:38 AM
Getting common dialog to work (re-install) Ragtime Access VBA 0 November 2nd, 2007 10:59 PM
How to use the flags int common dialog box diegoblin Beginning VB 6 2 November 8th, 2006 02:41 PM
Using common dialog with access azkabancells VB Databases Basics 2 May 14th, 2005 06:01 AM
Instantiating Common Dialog Box Dhodie Pro VB 6 2 July 19th, 2004 04:28 AM



All times are GMT -4. The time now is 04:02 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.