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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

.ConnectionString = "(...);Data Source=|DataDirectory|\SUPPLIER_QUOTATION.mdb"
The use of |DataDirectory| instead of Application.StartupPath.
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.
This is a common feature, not related to a specific language. It comes from System.Data.Common.DbConnectionOptions
Common for .Net. But not on VBA ;(. As a compensation, Ms Access has SubForms (and I won't swap them for .Net) :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.