Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6.0 .DBF IV Question

Posted on 2007-03-30
6
Medium Priority
?
1,119 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

604 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