Solved

VB6.0 .DBF IV Question

Posted on 2007-03-30
6
1,030 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
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:stcindia
Comment Utility
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)
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Read about achieving the basic levels of HRIS security in the workplace.
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…
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now