Computing.Net > Forums > Programming > More VB6 Help Please?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

More VB6 Help Please?

Reply to Message Icon

Name: DON
Date: August 29, 2002 at 05:48:17 Pacific
Comment:

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.???



Sponsored Link
Ads by Google

Response Number 1
Name: VBKing(ish)
Date: August 29, 2002 at 07:02:29 Pacific
Reply:

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.



0

Response Number 2
Name: New Guy
Date: August 29, 2002 at 11:57:55 Pacific
Reply:

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 Number

With tablename
If .State = 1 Then .Close
.Source = sSQL
.ActiveConnection = project
.CursorType = adOpenDynamic
.LockType = adLockPessimistic
.Open
End With
If tablename.EOF = True Then
gettablefield2 = ""
Else

gettablefield2 = projects(0)
End If
End Function

Then 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 Sub

Then 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


0

Response Number 3
Name: Madman
Date: September 5, 2002 at 22:46:15 Pacific
Reply:

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 =


0

Response Number 4
Name: Madman
Date: September 5, 2002 at 22:47:48 Pacific
Reply:

Oops...disregard everything after 'good luck'.

sorry.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: More VB6 Help Please?

Assembly Language Help please? www.computing.net/answers/programming/assembly-language-help-please/4705.html

help please www.computing.net/answers/programming/help-please/8283.html

classes interface in VB6 (abstract) www.computing.net/answers/programming/classes-interface-in-vb6-abstract/6017.html