0

When I run my program in Visual Studio, The message pops up, The file name and the file name in the Visual Basic is the same SUPPLIER_QUOTATION.

I already tried renaming the file but did not seems to work.

Public Sub connection()
    cn = New OleDb.OleDbConnection
    With cn
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "SUPPLIER_QUOTATION.mdb"
        .Open()
    End With
End Sub

Could not find file 'C:\Users\Patrick Echenique\Documents\Visual Studio 2012\Projects\SUPPLIER QUOTATION\SUPPLIER QUOTATION\bin\DebugSUPPLIER_QUOTATION.mdb'.

How do I solve the problem?

Emma
  • 27,428
  • 11
  • 44
  • 69

1 Answers1

1

You miss a backslash\in front of filename!

Path should be:

C:\Users\Patrick Echenique\Documents\Visual Studio 2012\Projects\SUPPLIER QUOTATION\SUPPLIER QUOTATION\bin\Debug\SUPPLIER_QUOTATION.mdb

Change code to:

.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
                    Application.StartupPath & "\SUPPLIER_QUOTATION.mdb"

UPDATE (suggested by @Jimi):

.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\SUPPLIER_QUOTATION.mdb"

I am not sure about the benefits of |DataDirectory|, but I am a novice in VB.Net.

ComputerVersteher
  • 2,638
  • 1
  • 10
  • 20
  • `.ConnectionString = "(...);Data Source=|DataDirectory|\SUPPLIER_QUOTATION.mdb"` – Jimi Jul 26 '19 at 06:25
  • 1
    The use of [|DataDirectory|](https://stackoverflow.com/a/12276625/7444103) instead of `Application.StartupPath`. – Jimi Jul 26 '19 at 06:49
  • No need for me to edit your answer. You already provided an example and a link, which includes the definition and specify its usage. Future readers may find your answer more useful this way. – Jimi Jul 26 '19 at 07:21
  • This is a common feature, not related to a specific language. It comes from `System.Data.Common.DbConnectionOptions ` – Jimi Jul 26 '19 at 07:33
  • Common for .Net. But not on VBA ;(. As a compensation, Ms Access has SubForms (and I won't swap them for .Net) :D – ComputerVersteher Jul 26 '19 at 07:38