473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Database problem

37
Hi there. I need some help in linking my Access database file to my program. I'm using a combo box which contains a list of names. But i have no idea on how to retrieve the database that consists the particulars of these names.
Jun 14 '07 #1
5 1263
debasisdas
8,127 Expert 4TB
Can you please specify wha exactly is your requirment.

do u want to retrive/display the details ,when u change the name

or u want to fill the combo itself by retriving data from the database.

Please do post back.
Jun 14 '07 #2
if you are populating the combo directly other than from database you may experience some problems. First, populate the combo with names directly from database using the following procedure
Expand|Select|Wrap|Line Numbers
  1. private sub populatenames(cmb as combobox)
  2.     dim cn as new adodb.connection
  3.     dim rec as new adodb.recordset
  4.  onerror goto errhandler
  5.     cn.connectionstring="DSN="nameofdsn"
  6.     cn.open
  7.  rec.open "select name from tbl",cn,adopendynamic,adlockoptimistic
  8.    cmb.clear
  9.     while rec.eof<>true
  10.       cmb.additem rec.fields(0)
  11.       rec.movenext
  12.     wend
  13. rec.close
  14. set rec=nothing
  15. cn.close
  16. set cn=nothing
  17. errhandler:
  18.      if err.number<>0 then
  19.          if err.number=3021 then
  20.            msgbox "No such name")
  21.         else
  22.            msgbox err.description
  23.          end if
  24.      end if
  25.  
  26. end sub
  27.  
  28.  
  29. call this procedure in the form activate event
  30.  
  31. and on the click event write the following code
  32.  
  33. dim cn as new adodb.connection
  34. dim rec as new adodb.recordset
  35. dim strsql as string
  36. cn.connectionstring="DSN=dsnname"
  37. strsql="select * from tblname where name=' "  & comboname.text & "'"
  38. cn.open
  39. rec.ope strsql,cn,adopendynamic,adlockoptimistic
  40.  
  41.  ' bind your code to the necessary controls
  42.  
  43. text1.text=rec.fields(0)
  44. text2.text=rec.fields(1)
  45.  
  46.  
  47. rec.close
  48. set rec=nothing
  49. cn.close
  50. set cn=nothing
  51.  
' be careful to check the status of the connection object before opening
Jun 15 '07 #3
tigger
37
Thanks for the reply. My database contains 10 names and their threshold values. When i select a name and click a "Present tone" button, it should show a smile if it corresponds to the threshold values in the database. I don't know how to link my database file to the program.
Jun 16 '07 #4
nairda
39
Thanks for the reply. My database contains 10 names and their threshold values. When i select a name and click a "Present tone" button, it should show a smile if it corresponds to the threshold values in the database. I don't know how to link my database file to the program.
Hi tigger,
First, it's better for you to get your combobox's list directly from your database. It means that every time your database changed (e.g: added new names or deleted a name), the combobox will be updated automatically.

To link your combobox to your database, you can use these codes:
Private Sub Form_Load()
Dim conec As New ADODB.Connection
Dim rs As New ADODB.Recordset

conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "\STUDENTS.mdb'"
conec.CursorLocation = adUseClient
conec.Open

rs.Open "select STUDENTNAME from STUDENTDATA", conec, adOpenKeyset, adLockOptimistic
If rs1.EOF = False Then
Do Until rs1.EOF
Combo1.AddItem rs!KD_SALES
rs.MoveNext
Loop
rs.Close
End If
End Sub

And to link your form to your database and show the data that match the name you've choosed in the textbox:
Private Sub Combo1_Click() '--> show the data straight away after you choose a name from combo1
Dim conec As New ADODB.Connection
Dim rs2 As New ADODB.Recordset

conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "\STUDENTS.mdb'"
conec.CursorLocation = adUseClient
conec.Open

rs2.Open "select * from STUDENTDATA where STUDENTNAME = '" & Combo1.Text & "'", conec, adOpenKeyset, adLockOptimistic
If rs2.EOF = False Then
Text1.Text = rs2!STUDENTNAME
Text5.Text = rs2!STUDENTADDRESS

rs2.MoveNext
rs2.Close
End If
End Sub

The bold text is used for show data from your database to textboxes. You may change it if you want to do other actions.

I hope it helps.
Nairda
Jun 18 '07 #5
tigger
37
Hey thanks.. But i encountered a problem opening the database at load event. I typed "conec.Open" but there's an error saying invalid password. Is it got to do with me adding a password in my access database?
Jul 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
7
by: Graham Taylor | last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it here also, as I think it might be the webserver which is causing my problem. --------- I have an Access 2003 database...
2
by: Robert McGregor | last post by:
Hi all, I've got a Front End / Back End database that was working just fine. One day i opened the FE to find that if I tried to open one of the linked tables from the database window, nothing...
19
by: adirat | last post by:
I have read a lot on this subject on newsgroups and other access related websites on data corruption, but since we are still not able to isolate the problem – I am posting this detailed explanation...
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
6
by: xeqister | last post by:
Greetings, We are having a situation here whereby one of our staff created a very huge 32K buffer pool in a production database and caused the database to go down. When we try to reconnect to the...
12
by: Steve | last post by:
I have a database that raises an error when you try to open it and it doesn't open. Trying to open the database with the OpenDatabase method raises the same error. Trying to import any objects...
4
by: raidvvan | last post by:
Hi there, We have been looking for some time now for a database system that can fit a large distributed computing project, but we haven't been able to find one. I was hoping that someone can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.