Solved

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

Posted on 2004-03-23
5
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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