Jump to content
Fórum Script Brasil
  • 0

Como Abrir Banco De Dados Access No Visual Basic


Guest --Luciane --
 Share

Question

Guest --Luciane --

Como faço para abrir Banco de Dados Access2003 no Visual Basic 6.0

Estou fazendo da seguinte forma:

Global db As Database

Global rdcli As Recordset

Private Sub Form_Load()

Set db = OpenDatabase(App.Path + "\dbintegracao.mdb", False, False)

Set rdcli = db.OpenRecordset("tab_cli", dbOpenDynaset)

End Sub

Porque não está dando certo?

Grata,

Luciane

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Ola Luciane,

Não sei se é a melhor maneira para fazer isso, mas para mim funcionou:

    Dim objAccess As Object
Dim endRelatorio , nomeBD ,nomeRelatorio, NomeTabela as String

endRelatorio = "c:\MinhaPasta\"
nomeBD = "Relatorio.mdb"
nomeRelatorio = "MeuRelatorio"
NomeTabela = "MinhaTabela"


Set objAccess = CreateObject("Access.Application")

With objAccess
.Visible = True
.OpenCurrentDatabase filepath:= endRelatorio & nomeBD
.DoCmd.OpenReport nomeRelatorio, acViewPreview, , NomeTabela
End With


.DoCmd.Maximize ' Para Maximizar o Access
.DoCmd.Maximize ' Para Maximizar o relatorio[/codebox]

Mas o DoCmd.Maximize não funcionou exatamente com eu gostaria :)

Espero ter ajudado.

Abraços,

Dory.

Link to comment
Share on other sites

  • 0

Bom,

A outra forma que consegui fazer funcionar foi:

   Dim strArquivo As String
Dim strLocal As String
Dim ConectaAccess As String

Set conexao = New ADODB.Connection
Set db = New ADODB.Recordset
Set conexao = CreateObject("ADODB.Connection")

strArquivo = "Arquivo.mdb"
strLocal = "c:\MinhaPasta\"

ConectaAccess = "Driver={Microsoft Access Driver (*.mdb)};" & "Dbq=" & strArquivo & ";" & "DefaultDir=" & strLocal & ";"""

conexao.Open ConectaAccess[/codebox]

Dory.

Link to comment
Share on other sites

  • 0

Use ADO (faça referência ao Microsoft ActiveX Data Objects 2.x):

Global cn As ADODB.Connection
Global rdcli As ADODB.Recordset

Private Sub Form_Load()

    set cn = new ADODB.Connection
    set rdcli = new ADODB.Recordset

    cn.CursorLocation = adUseClient
    rdcli.CursorLocation = adUseClient

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="App.Path + "\dbintegracao.mdb"
    rdcli.Open "SELECT * FROM tab_cli", cn, adOpenDynamic, adLockBatchOptimistic
End Sub

Certo? ;)

Graymalkin

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      151k
    • Total Posts
      649.1k
×
×
  • Create New...