Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2005, 03:54 PM
Registered User
 
Join Date: May 2005
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
 
Old May 25th, 2005, 10:34 AM
Friend of Wrox
 
Join Date: Nov 2004
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.





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 03: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.