Solved

VB6.0 .DBF IV Question

Posted on 2007-03-30
6
1,069 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
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Viewers will learn the different options available in the Backstage view in Excel 2013.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 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