Hi,

Im new to VB. Im creating a windows application that computes for certain figures which i plan to save and have this information sent to ms access 07. I know how to connect the databases.

My problem is that when i placed in the save command, it doesnt show in acess and the data is turned into a lbl file or something.

this is the code for save:

Dim SaveFileDialog1 As SaveFileDialog = New System.Windows.Forms.SaveFileDialog

With SaveFileDialog1
.DefaultExt = ".mdb"
.Filter = "access database|*.mdb"
.InitialDirectory = "desktop"
End With

If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Console.WriteLine(SaveFileDialog1.FileName)
End If

when i click on save, it tells me if i want to overwrite the changes in access. when i click yes, it does not go into the program but creates another one. when i try to open it, the computer tells me this is a lbl file making it impossible for me to view.

i need to learn how to do this because i will be inputting data on a monthly basis. can someone help me?

pls try to show me an example of explain it in a way that a beginner like myself can understand.

thanks so much.

hi

Try the Below codings,
import system.io
'Reference - Microsoft Access 10.0 Object Library
SaveFileDialog1.Filter = "(*.mdb)|*.mdb"
SaveFileDialog1.ShowDialog()
Dim file As String
file = SaveFileDialog1.FileName
Dim accessfile As New Access.Application
Dim fs As File
If fs.Exists(file) Then
According to me not able to replace the existing file by new one so that i delete the existing file and created a new one.
fs.Delete(file)
accessfile.NewCurrentDatabase(file)
accessfile.CloseCurrentDatabase()
Else
accessfile.NewCurrentDatabase(file)
accessfile.CloseCurrentDatabase()
End If

Best Regards,
Shailu:)

hi,

thanks but it still doesnt work. i copied paste what you wrote and these are the errors that came out.

Error 1 Name 'import' is not declared.
Error 2 'System.IO' is a namespace and cannot be used as an expression.
Error 3 Name 'SaveFileDialog1' is not declared.
Error 4 Name 'SaveFileDialog1' is not declared.
Error 5 Name 'SaveFileDialog1' is not declared.
Error 6 Type 'Access.Application' is not defined.
Error 7 Type 'File' is not defined.

as you can see, there are 7 errors. any advice?

hi

Try the Below codings,
import system.io
'Reference - Microsoft Access 10.0 Object Library
SaveFileDialog1.Filter = "(*.mdb)|*.mdb"
SaveFileDialog1.ShowDialog()
Dim file As String
file = SaveFileDialog1.FileName
Dim accessfile As New Access.Application
Dim fs As File
If fs.Exists(file) Then
According to me not able to replace the existing file by new one so that i delete the existing file and created a new one.
fs.Delete(file)
accessfile.NewCurrentDatabase(file)
accessfile.CloseCurrentDatabase()
Else
accessfile.NewCurrentDatabase(file)
accessfile.CloseCurrentDatabase()
End If

Best Regards,
Shailu:)

hi,

Error 1 Name 'import' is not declared.

U have to write the namespace in the outside of the procedures that is it should be top of the coding in the form.

Error 2 'System.IO' is a namespace and cannot be used as an expression.
Error 7 Type 'File' is not defined.
U have to write the namespace in the outside of the procedures that is it should be top of the coding in the form.
write it in the single line " Imports System.IO"
While typing the keyword "Imports" and then press spacebar u wil get the list of namespaces.

If u given properly u wil definetly get the "file".

Error 3 Name 'SaveFileDialog1' is not declared.
Error 4 Name 'SaveFileDialog1' is not declared.
Error 5 Name 'SaveFileDialog1' is not declared.


U have to drag and drop the savefiledialog control from the toolbox to the form.

Error 6 Type 'Access.Application' is not defined.
u have to give the reference for that "access.application"
1. Project -> Add Reference
2. One Dialog Box will display then Select "COM" Tab.
3. Select "Microsoft Access 10.0 Object Library"
4. Click select
5. Click Ok

Modify the code according to my suggestions. Still u didn't get mean then i will send u the application. k

Best of luck
Have a Nice Day

Best Regards,
Shailu:)


hi,

thanks but it still doesnt work. i copied paste what you wrote and these are the errors that came out.

Error 1 Name 'import' is not declared.
Error 2 'System.IO' is a namespace and cannot be used as an expression.
Error 3 Name 'SaveFileDialog1' is not declared.
Error 4 Name 'SaveFileDialog1' is not declared.
Error 5 Name 'SaveFileDialog1' is not declared.
Error 6 Type 'Access.Application' is not defined.
Error 7 Type 'File' is not defined.

as you can see, there are 7 errors. any advice?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.