Solved

Getting random information from a database

Posted on 2002-04-09
6
141 Views
Last Modified: 2010-05-02
           

           1st textbox   =  Name
            2nd textbox =  Father?s name
            3rd textbox  =  House No
            4th textbox =   Street No
            5th textbox =   City
               
   Over here I have got five textboxes(on a vb form) showing addresses of a city.
    How can I get ?Name?  ?Fathername? ?Street? and City by writing only the ?House No? and  Clicking for example I want to get information about house no 123 ,  50 and  780  one at a time from the connected Database.
 
0
Comment
Question by:HIKER
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:telebasics
ID: 6929856
using SQL a statement like:
SELECT * FROM database WHERE streetno IN '123','50','780'

not sure about the IN but something like that.
0
 

Author Comment

by:HIKER
ID: 6929916
   
    Not answered yet
0
 

Accepted Solution

by:
humbk2002 earned 50 total points
ID: 6930645
Below is the solution,House no should be shown in a combo box,because you are to use it to make selections,the house numbers will be shown on the combo box,so with that you can select a house no,and then the rest can be shown on the separate text boxes,but try this code:


---------------------------Load the Form`````````````````
Private Sub Form_Load()
Set db = OpenDatabase("Yourdatabase.mdb")
Set RS = db.OpenRecordset("tabel or query to show the items")
Do While RS.EOF = False
'cmbHouseno is the combo box name and Houseno is the table 'or query field so add it

cmbHouseno.AddItem RS!Houseno

RS.MoveNext
End Sub

-------------The function to show the next fields`````
Public Function FillRelated_Information()
Dim found as Boolean
found = False
If cmbHouseno <> "" Then
Set db = OpenDatabase("Yourdatabse.mdb")
Set RS = db.OpenRecordset("table/query")
Do While Not RS.EOF And Not found
If cmbHouseno = RS!HouseNo Then
found = True
Else
RS.MoveNext
End If
Loop
End If
If found = True Then
'Put the data into the text boxes and combo box
 'Put the contents in the appropriate boxes
txtName=RS!Name
txtfathername=RS!Fathersname
txtCity=RS!City
RS.Edit
cmbHouseno=RS!Houseno

RS.Update
End If
End Function

```````````````````````Call Function```````````````
Private Sub cmbHouseno_click()
Call FillRelated_Information
End sub
```Hopes it helps`````````````````````````````````

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:humbk2002
ID: 6930646
include also this code

txtStreetno=RS!Streetno
0
 

Author Comment

by:HIKER
ID: 6932262
   I want to make it simple
   On a vb form I have a data control which is connected to
  ?NWIND? (the sample data which comes with vb) I have
  chosen ?employees? from data source.
  I have got six textboxes showing 1 employees ID  
  2 last name 3 first name 4 title 5 title of courtesy
  6 birthday it is working ok I can scroll from id no 1 to id  
   no 9  but I want to write the id no of my choice and get
   other related information in other textboxes.
     
   
0
 

Author Comment

by:HIKER
ID: 6932267
 oops
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now