Solved

VB6.0 .DBF IV Question

Posted on 2007-03-30
6
1,103 Views
Last Modified: 2013-11-24
I am using VB6 sp6.
XP Pro OS

Microsoft DAO 3.1 Object Lib.

Basically I want to load a .dbf file with a command button.  It will get the full path from a textbox.
Everything is up to date with versions. I get a isam 3170 error. Can it be done this way? or do i have to use ADO? I never used ado.... If so can you please edit my code.  Here is a sample.





Private Sub Command1_Click()

Dim txtdbf As String
Dim txtxls As String
Dim txtloc As String

Dim db As Database
Dim rs As Recordset
dim txtloc as string

txtdbf = Text1.Text
txtxls = Text2.Text
txtloc =  text3.text


Set db = OpenDatabase(txtloc, True, False, "dBASE 4.0")
Set rs = db.OpenRecordset("rt120106")
txtdbf = rs.Fields("IBette")

10
If txtdbf = txtxls Then GoTo 20
If txtdbf > txtxls Then GoTo 90
If txtdbf < txtxls Then GoTo 30


20
rs.Delete
rs.MoveNext
If Text1.Text = Text2.Text Then GoTo 20
If Text1.Text > Text2.Text Then GoTo 90
If Text1.Text < Text2.Text Then GoTo 10

30 rs.MoveNext

90 MsgBox "DONE!"

End Sub


0
Comment
Question by:daneburr
[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
6 Comments
 
LVL 4

Expert Comment

by:stcindia
ID: 18828110
You can connect using following method

Private Sub Command1_Click()

Dim txtdbf As String
Dim txtxls As String
Dim txtloc As String
Dim ConnStr as String

Dim db As new connection
Dim rs As new Recordset
dim txtloc as string


txtdbf = Text1.Text
txtxls = Text2.Text
txtloc =  text3.text

' *** You Need to create ODBC DSN, (I have created Named Test), You should select Microsoft dBase Driver (*.dbf) ***

ConnStr= "Provider=MSDASQL.1;Persist Security Info=False;Extended Properties=DSN=Test;DBQ='" & txtloc & "';DefaultDir='" & txtLoc & "';DriverId=277;FIL=dBase IV;MaxBufferSize=2048;PageTimeout=5;"

db.open ConnStr
rs.open "select * from rt120106", db, adOpenDynamic, adLockOptimistic
txtdbf = rs.Fields("IBette")

10
If txtdbf = txtxls Then GoTo 20
If txtdbf > txtxls Then GoTo 90
If txtdbf < txtxls Then GoTo 30


20
rs.Delete
rs.MoveNext
If Text1.Text = Text2.Text Then GoTo 20
If Text1.Text > Text2.Text Then GoTo 90
If Text1.Text < Text2.Text Then GoTo 10

30 rs.MoveNext

90 MsgBox "DONE!"

End Sub
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 18828113

http://support.microsoft.com/kb/210259

'display a test of txtloc to make sure it is reasonable
Msgbox "!" & txtloc & "!"    'make sure it's not blank

Set db = OpenDatabase(txtloc, true , False, "dBASE IV;")    'note the  ; at the end

0
 

Author Comment

by:daneburr
ID: 18886751
This did not work.  Everything loads but the textbox's do not populate.  It seems as if the dbase does not really load.  What am i doing wrong?
0
 
LVL 4

Expert Comment

by:stcindia
ID: 18887447
Try hard code the database name, if that works use
Set db = OpenDatabase(rtrim(txtloc), True, False, "dBASE 4.0")
trim the txtloc, may be spaces at the end of text prevents opening up the data
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 18887516
How are the textboxes linked to your DB ?  They dont appear to be datalinked. (which is fine)

The code provided doesnt seem to do so. And need to get rid of the GOTO's . they dont make sense.

'---------------------------------------------
Private Sub Command1_Click()

Dim txtdbf As String
Dim txtxls As String
Dim txtloc As String

Dim db As Database
Dim rs As Recordset
dim txtloc as string

txtdbf = Text1.Text
txtxls = Text2.Text
txtloc =  text3.text


Set db = OpenDatabase(txtloc true , False, "dBASE IV;")    'note the  ; at the end
Set rs = db.OpenRecordset("rt120106")

do while not eof(rs)
        txtdbf = rs.Fields("IBette")


        If txtdbf = txtxls Then
           rs.Delete      'dont know if this does MoveNext intrinsically
         elseif txtdbf > txtxls Then
            exit do      'stop processing
        else
            ' txtdbf < txtxls
            'do nothing
       end if

       rs.MoveNext
loop

rs.close

MsgBox "DONE!"

End Sub


' comparing text fields using < > is done alphabetically.   ie   2 is greater than 18
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

688 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