6 Replies - 2855 Views - Last Post: 25 February 2011 - 07:49 AM

#1 pal121   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-February 06

Open & Saving .txt files

Posted 10 February 2006 - 01:06 PM

Description: copy & paste & add Microsoft Common Dialog Control 6.0 you need a button and a textboxhow to open and save text files
Private Sub cmdsave_Click()

Dim filelocation As String

' loads save as box
    commondialog1.ShowSave
    
    filelocation = commondialog1.FileName
    
' append saves over file if it assists
    Open filelocation For Append As #1
        Print #1, text1.text
    Close #1

End Sub

Private Sub cmdopen_Click()

Dim filelocation As String

' show open box
    commondialog1.ShowOpen
    
    filelocation = commondialog1.FileName
 
' input files into text1.text   
    Open filelocation For Input As #1
    
Do Until EOF(1)

        Input #1, Data
        text1.text = text1.text + Data + vbNewLine
    EOF (1)
    Loop
    Close #1
    
End Sub





Is This A Good Question/Topic? 0
  • +

Replies To: Open & Saving .txt files

#2 karlamohan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-July 08

Re: Open & Saving .txt files

Posted 26 July 2008 - 02:51 AM

database in MSAccess has been connected I want to open a document in wordpad format. the file address is in a field of access. Private Sub Form_Load() Set DB = DBEngine.OpenDatabase("C:\Documents and Settings\madhu\My Documents\dbdbase.mdb") Set RS = DB.OpenRecordset(" Select * from tblBdata ") MsgBox "Database connected" Call Disp End Sub Private Sub Disp() txtStNo.Text = RS!stno txtName.Text = RS!Name txtDesgn.Text = RS!desgn txtbiodn.text = Rs!biodtfn End Sub
Was This Post Helpful? 0
  • +
  • -

#3 akhileshbc   User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 179
  • Joined: 27-September 08

Re: Open & Saving .txt files

Posted 28 September 2008 - 01:20 AM

Append means adding the new data to the end of the file. Output means, replacing the whole textfile with the new data. :)
Was This Post Helpful? 0
  • +
  • -

#4 akhileshbc   User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 179
  • Joined: 27-September 08

Re: Open & Saving .txt files

Posted 30 September 2008 - 10:12 PM

The loop can be something like this also: While Not EOF(1) Line Input #1, Data Text1.Text=Text1.Text & Data & vbNewLine Wend
Was This Post Helpful? 0
  • +
  • -

#5 paperclipmuffin   User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: Open & Saving .txt files

Posted 16 April 2009 - 10:36 PM

I cant get it to work for me. When i run, it crashes and highlights the "commondialog1.showsave" saying "object required". Help anyone?
Was This Post Helpful? 0
  • +
  • -

#6 binyamin   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-July 09

Re: Open & Saving .txt files

Posted 01 July 2009 - 12:39 PM

You just need to add this control and put it somewhere on your form: 1) Goto Project --> Components . . . 2) Scroll down and make sure Microsoft Common Dialog control 6.0 (SP6) is checked. 3) Click OK 4) This will add the CommonDialog control to your to your toolbar. 5) Find the icon for CommonDialog. It looks kinda like a page from a Powerpoint presentation or old radio. It will be outlined in black. 6) Once you locate it, add one to your form. It will not show up as an icon when you run your program, but it will allow you to open up a saveas window, etc. 7) Rerun your program. It should work now. Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#7 Azrie   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-February 11

Re: Open & Saving .txt files

Posted 25 February 2011 - 07:49 AM

Private Sub Command2_Click() If File1.FileName = "" Then MsgBox "Please select directory and file name", vbExclamation, "Missing" Else Call ShellExecute(hWnd, "Open", Dir1.Path & "\" & File1.FileName, "", App.Path, 1) End If End Sub please help me.i want to create command button to open the file. but when i run they said sub and function not define..please help me to solve that problem...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1