Solved

Getting random information from a database

Posted on 2002-04-09
6
130 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
Comment Utility
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
Comment Utility
   
    Not answered yet
0
 

Accepted Solution

by:
humbk2002 earned 50 total points
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Expert Comment

by:humbk2002
Comment Utility
include also this code

txtStreetno=RS!Streetno
0
 

Author Comment

by:HIKER
Comment Utility
   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
Comment Utility
 oops
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 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

10 Experts available now in Live!

Get 1:1 Help Now