Link to home
Start Free TrialLog in
Avatar of daneburr
daneburrFlag for United States of America

asked on

VB6.0 .DBF IV Question

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


Avatar of stcindia
stcindia
Flag of India image

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
Avatar of Robberbaron (robr)

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

Avatar of daneburr

ASKER

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?
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
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial