|
-
Sep 25th, 2000, 04:18 PM
#1
Thread Starter
Junior Member
I am just beginning to try and do some database stuff and have run in to a problem. I can't get the data from my datasource to show up in my bound text box. The data source is selected by the user from a file open dialog box, when they select the file, the datasource property of data1 is set to that file. The datasource property of my text box is set to data1. In my code after the user selects the file i have text2.datafield = "MARKET". Market is the name of the column that holds the cell i want to be displayed in the text box. can anyone help me please? Just beginning so anything will be appreciated.
Thanks in advance.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 04:58 PM
#2
Fanatic Member
hi
If you can state what you're trying to do as well
then I would probably understand a bit clearer your question
I want to help if I can...
Let me know
-
Sep 25th, 2000, 05:02 PM
#3
Thread Starter
Junior Member
i have a text box called text2. My database is called data1 and is a .dbf file. i want to know through code, how to get the contents of a cell from the database to show up in the text box.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 05:21 PM
#4
_______
<?>
Code:
'here is some code to open a db and put your field
'in a text box
'*******************************
'change yourdatabasename to the name of your database
'change yourtablename to the name of the table in your databas
'change yourfieldname to the name of the field in your database
'********************************
'add a data control to a form Data1
'add a textbox to the form Text1
'set the Datasource Property of Text1 to Data1
'copy and paste this code after changing the names above
'
'run the app.
Option Explicit
'open database and set database and recordset
Public db As Database, rs As Recordset
Public cTblName As String
Public cdbName As String
Public Sub OpenDB()
Dim AppPath$
If Right(App.Path, 1) <> "\" Then _
AppPath = App.Path & "\" _
Else AppPath = App.Path
cdbName = AppPath & "YourDatabaseName.mdb"
cTblName = "YourTableName"
Data1.DatabaseName = cdbName
Data1.RecordSource = cTblName
Text1.DataField = "yourfieldname"
Data1.Refresh
End Sub
Private Sub Form_Load()
'
Call OpenDB
'
Set db = Workspaces(0).OpenDatabase(cdbName)
Set rs = db.OpenRecordset(cTblName)
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 05:32 PM
#5
Thread Starter
Junior Member
'change yourfieldname to the name of the field in your database
what would the name of my field be? the item in it or coordinates or something? the name of the column in the database file is MARKET. the item in the first cell is SANJ. I am trying to get it to display the SANJ in the text box.
sorry if this is troublesome.
thank you
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 05:35 PM
#6
_______
<?>
Your fieldname must be Market
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 05:45 PM
#7
Thread Starter
Junior Member
that doesnt seem to be working
here is the code for my form:
Dim iHeight As Integer
Dim iWidth As Integer
Public db As Database, rs As Recordset
Public cTblName As String
Public cdbName As String
========================================
Private Sub cmdBalance_Click()
frmBalance.Show
Unload Me
End Sub
========================================
Private Sub cmdQuit_Click()
Unload Me
End
End Sub
========================================
Private Sub Form_Load()
iHeight = Me.Height
iWidth = Me.Width
End Sub
========================================
Private Sub Form_Resize()
On Error Resume Next
Me.Height = iHeight
Me.Width = iWidth
End Sub
========================================
Private Sub Open_Click(Index As Integer)
On Error GoTo ErrHandler
'set filters
CommonDialog1.Filter = "DBF (*.dbf)|*.dbf"
'display file open box
CommonDialog1.ShowOpen
Data1.DatabaseName = CommonDialog1.filename 'sets database as selected file
Call OpenDB
'
Set db = Workspaces(0).OpenDatabase(cdbName)
Set rs = db.OpenRecordset(cTblName)
ErrHandler:
Exit Sub
End Sub
========================================
Public Sub OpenDB()
Dim AppPath$
If Right(App.Path, 1) <> "\" Then _
AppPath = App.Path & "\" _
Else AppPath = App.Path
cdbName = AppPath & CommonDialog1.filename
cTblName = "MARKET"
Data1.DatabaseName = cdbName
Data1.RecordSource = cTblName
Text2.DataField = "MARKET"
Data1.Refresh
End Sub
========================================
when i run the project as is it will run but nothing shows up in the text box (text2) when i select the database.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 05:51 PM
#8
_______
<?>
zip your application and your database and send it to me.
I will test it from my end.
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 05:58 PM
#9
Thread Starter
Junior Member
you should have it any time, i just sent the project to you. please post any questions or comments here.
thank you for your time.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 06:03 PM
#10
_______
<?>
you forgot to send the database.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 06:06 PM
#11
Thread Starter
Junior Member
should be there in the badhaiku.zip called test.dbf, i will resend though.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 06:12 PM
#12
_______
<?>
My error..I was looking for MDB What program opens the dbf
I can import it into Access if I know what it is.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 06:16 PM
#13
Thread Starter
Junior Member
thats a dbase 4 file. you can open it with excel if you just want to see the structure, or with the visual data manager add in in vb.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 06:47 PM
#14
_______
<?>
OK it's Fox Pro..I imported it..your table name is test and your fieldname is Market...
I don't know where to start. First off, you are accessing a database using a commondialog is great, but how do you expect to get the table names to associate with opening the recordsets...ie..some databases have multiple tables, multiple fields etc.
[code]
Public Sub OpenDB()
Dim AppPath$
cTblName = "test"
If Right(App.Path, 1) <> "\" Then _
AppPath = App.Path & "\" _
Else AppPath = App.Path
Data1.DatabaseName = cdbName
Data1.RecordSource = cTblName
End Sub
[\code]
'*********************************************************
'I'm not sure where you pulled this from so I stuck it in
'a commandbutton for testing purposes.
'I've changed it as well
Code:
Private Sub Open_Click(Index As Integer)
On Error GoTo ErrHandler
'set filters
CommonDialog1.Filter = "DBF (*.dbf)|*.dbf"
'display file open box
CommonDialog1.ShowOpen
cdbName = CommonDialog1.FileName 'sets database as selected file
Data1.DatabaseName = cdbName
Call OpenDB
'
Set db = Workspaces(0).OpenDatabase(cdbName)
Set rs = db.OpenRecordset(cTblName)
frmGlobal.Data1.Refresh
Text2.DataField = "Market"
ErrHandler:
Exit Sub
End Sub
'*******************************************************
'
'I had to check this using acess so I changed the property
'of connection to Access and it works.
'
I can't test it with other as I don't have it...but it did put your name in the box SANJ
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 07:35 PM
#15
Thread Starter
Junior Member
could you please mail the project back to me with the changes that you made intact so that i can check it out. When i make the changes posted here in the code with connect set to access it still isnt working.
thanks.
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 25th, 2000, 08:09 PM
#16
_______
<?>
Sorry, I deleted them after testing ...if you set it to access you must have and access database not a fox pro. and you must set the connection property of the data control to
Access
also change the filter to refect Access DataBase
'set filters
CommonDialog1.Filter = "MDB (*.mdb)|*.mdb"
you can create an Access MDB by going to AddIns DataManager and using Access..you will have to visit the help section on that though because I just use MsAccess
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|