Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Thanks for all the previous help guys!! Here is where I am. I have a VB app with two forms (frm1) and (frm2) both forms have the same underlying db table. frm1 is used to input data to the table. when you get to a field (text1) on frm1 you enter a ID number. On the (lostFocus) of frm1.text1 I have told frm2 to open with this code.(frm2.show). Now frm2 has 5 text fields. I need frm2 to open and display all five fields of info according to the ID number value on frm1. I have placed the following code in the (load) of frm2 DIM ID as string//ID=frm1.text1.text.When this is executed, frm2 does open but only shows data in the ID field and not the other selected data.???

This may sound strange, but have you told the program what should be in these text boxes on form2.
The way that I use VB and a database is to use purely code rather data enviroments or anything else. I'm guessing that form1 takes the ID number from the user, form2 then displays its relevant information i.e. ID number, person name etc based on the database contents.
Have you just used code to get this far? If so you would use a WITH statement and a FIND on the ID Number within the RECORDSET and retrieve each field using for example text2.text = !Name (where name is the database field for that record). That is of course presuming that the details have been entered in the actual database.
Remember that if you just use the DIM statement within one form then the variable scope is only within that form, that maybe the answer to your question.
Or have I just got completely the wrong idea???!
Post back or E-Mail me if you need anything else.

Try putting something like this in a module
Function gettablefield2(ID NUMBER As String) As String
'The ID Number is the name of the field in your table
Dim tablename As New ADODB.Recordset
Dim project As New ADODB.Connection
Dim sSQL As String
Set project = CurrentProject.Connection
sSQL = " select tablefield2 from [tablename] where [ID Number] = " & ID NumberWith tablename
If .State = 1 Then .Close
.Source = sSQL
.ActiveConnection = project
.CursorType = adOpenDynamic
.LockType = adLockPessimistic
.Open
End With
If tablename.EOF = True Then
gettablefield2 = ""
Elsegettablefield2 = projects(0)
End If
End FunctionThen put this in your form load event for form2
Private Sub Form_Load()
If ("" & txtfield2.Value) = "" Then
txtfield2.Value = gettablefield2(txtIDNumber.Value)
End If
End SubThen just put the same code in for the other fields that need to populate.
Keep in mind I am still new so you may need to make a few adjustments but hopefully that will get you started.
Post back and let me know how it goes
New Guy

If you are using Access and want to display data from the table based the ID entered, why not try using a Data object bound to the table, with each textbox bound to the respective field in the table.
I have used this approach with great success, using a 'pop-up' type form to get the id which is then used to refresh the data object recordset.
If the other suggestions are not suitable, email me and I will help you in any way I can. What you are trying to do is very doable and not at all difficult.
good luck.
place a Data object on form2, visible=false.
bind each textbox to the appropriate field in the table.
after the id is entered, perform a seek or sql on the table using the id.
if you get a match, set Data.recordset =

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |