RSS Forums RSS
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums

vb6/common dialog/access db

Join Date: May 2005
Posts: 6
Reputation: azkabancells is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
azkabancells's Avatar
azkabancells azkabancells is offline Offline
Newbie Poster

Help vb6/common dialog/access db

  #1  
May 21st, 2005
I am undertaking a project but am hopelessly stuck. :cry: I have trawled the net, read books and followed tutorials but I just can't move forward. I would be really grateful if someone could help.

I need to create a sequential name and address file with the following options:

open a new file

open an existing file

add name and address info to open file

close a file

exit the program.

There are defined guidelines that I have so far stuck to. What I think I need to do is change my coding so I have an embedded db template that I can use to create a new db or open an existing db.

My code is as follows-

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        &n bsp;         &n bsp;         '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
Ty for looking.
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:25 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC