Solved

how do I handle an Access 95 table through VB6 running on XP?

Posted on 2004-03-23
5
255 Views
Last Modified: 2013-12-25
I am running XP Pro with Access 2000.  Access will allow me to append records through the table view, but I can't create any new form, report, query etc.  I do have VB6.  An Access expert suggested I use the MS Jet Engine.  I downloaded it, but didn't install it yet.  I am unfamiliar with the product.  Using debug -d I noticed that the Access file was created or modified at some point by Jet engine.  The file is used as an overlay to legacy mapping program called Falconview.
What I wish to do is create a form for end users to append map point data to this file, then be able to query and run reports against it.  This is urgently needed.
Thank you,
Russ
0
Comment
Question by:RUSS_EMI
  • 2
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:MYLim
MYLim earned 150 total points
ID: 10655965
'here are the code that i use to
'connect Access2000 database
'through Jet Engine

Dim Cnn As ADODB.Connection
Dim Rs As ADODB.Recordset
 
Private sub form_load()
On error goto ErrFound
Set Cnn = New ADODB.Connection
Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyProgram\Hprecorder\HpRecorder.mdb;User Id=admin;Password=;"

Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
Rs.Open "Select distinct dono from invkeep group by dono order by dono asc", Cnn, adOpenStatic, adLockReadOnly

if Rs.eof = true then
 msgbox "Empty Recordset,Connection will be Close"
 rs.close
 set rs=  nothing

  Cnn.close
 set Cnn = nothing
 
 exit sub
end if

debug.print rs.fields(0).value & " "

 rs.close
 set rs=  nothing

  Cnn.close
 set Cnn = nothing
 
 exit sub
ErrFound:
msgbox "Err description : " & Err.Description
if rs.state=adstateOpen Then
  rs.close
  set rs = nothing
end if
 
if Cnn.state = adstateOpen then
  Cnn.close
  set Cnn = nothing
end if
end sub
0
 
LVL 8

Expert Comment

by:MYLim
ID: 10655976
Beside that,Please :
1.Update VB6 Latest service Pack -> SP5
2.Update MDAC to latest verison -> MDAC2.8
3.Latest Jet Engine Service Pack ->8.0

0
 

Author Comment

by:RUSS_EMI
ID: 10656084
Thank you.  Does this code allow for appending, if not would you show a sample?
My table only consists of 4 items; ID, Latitude, Longitude and Description.
Russ
0
 
LVL 1

Assisted Solution

by:schmucje
schmucje earned 350 total points
ID: 10664198
Here are two different ways you can append the records to the table

Private cnnAccess As ADODB.Connection
Private rstAccess As ADODB.Recordset
Private Const sAccessPassword As String = """"
Private Const sFilePath As String = ""somepath""
Private Const sFileSpec As String = ""db1.mdb""
Private Const sDataSource As String = sFilePath & sFileSpec
private Const sProvider As String = ""Microsoft.Jet.OLEDB.4.0""

Private Sub AppendBySQL()
 
  Set cnnAccess = New ADODB.Connection
  With cnnAccess
    .Provider = sProvider
    .Properties(""Jet OLEDB:Database Password"") = sAccessPassword
    .ConnectionString = sDataSource
    .Open
  End With

  cnnAccess.Execute "INSERT INTO tblMaps (id, lattitude, longitude, description) " & _
                              "VALUES " & _ txtId.Text & ", " & txtLat.Text & ", " & txtLon.Text & ", " & txtDesc.Text
 
  If Not cnnAccess Is Nothing Then
    If cnnAccess.State = adStateOpen Then
      cnnAccess.Close
    End If
    Set cnnAccess = Nothing
  End If

End Sub

Private Sub InsertByADORecordset()
 
  Set cnnAccess = New ADODB.Connection
  With cnnAccess
    .Provider = sProvider
    .Properties(""Jet OLEDB:Database Password"") = sAccessPassword
    .ConnectionString = sDataSource
    .Open
  End With

Set rstAccess = New ADODB.Recordset
  With rstAccess
    .LockType = adLockPessimistic
    .CursorLocation = adUseServer
    .CursorType = adOpenKeyset
    .ActiveConnection = cnnAccess
  End With

  cnnAccess.Execute "INSERT INTO tblMaps (id, lattitude, longitude, description) " & _
                              "VALUES " & _ txtId.Text & ", " & txtLat.Text & ", " & txtLon.Text & ", " & txtDesc.Text
 
  If Not cnnAccess Is Nothing Then
    If cnnAccess.State = adStateOpen Then
      cnnAccess.Close
    End If
    Set cnnAccess = Nothing
  End If

End Sub
0
 
LVL 1

Accepted Solution

by:
schmucje earned 350 total points
ID: 10664222
I accidentally hit enter before finishing the InsertByADORecordset.

Private Sub InsertByADORecordset()
 
  Set cnnAccess = New ADODB.Connection
  With cnnAccess
    .Provider = sProvider
    .Properties(""Jet OLEDB:Database Password"") = sAccessPassword
    .ConnectionString = sDataSource
    .Open
  End With

  Set rstAccess = New ADODB.Recordset
  With rstAccess
    .LockType = adLockPessimistic
    .CursorLocation = adUseServer
    .CursorType = adOpenKeyset
    .ActiveConnection = cnnAccess
  End With

  rstAccess.AddNew
  rstAccess("id").value = txtId.Text
  rstAccess("lattitude").value = txtLat.Text
  rstAccess("longitude").value = txtLon.Text
  rstAccess("description").value = txtDesc.Text
  rstaccess.Update
   
  If Not rstAccess Is Nothing Then
    If rstAccess.State = adStateOpen Then
       rstAccess.Close
    End If
    Set rstAccess = Nothing
  End If
 
  If Not cnnAccess Is Nothing Then
    If cnnAccess.State = adStateOpen Then
      cnnAccess.Close
    End If
    Set cnnAccess = Nothing
  End If

End Sub

The checking of the ADO "states" before closing is a little overkill when it is within the same procedure as the open, but I usually have it in a seprate procedure.  I just copied and pasted here.

HIH,
joe
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now