I know how to pass a single text from one form to another form
1- declare a public variable in the general part of the form like this
public varaiableName as String
2- in the form_load() write
variableName=text1.text
3- you can access this variable from any other form using the form name

lets say you have form2 and you want to pass text1.text which is in form1 to form2 which has a text feild (text2)

you can do that like this:-

text2.text=form1.variableName.


This helps in copying a single text.But I need to display all data from form2 in form1 using a listbox.
I am new to VB6.How do i do it???pl help...

Recommended Answers

All 14 Replies

Check whether the attached code helps you to get your answer or not.

Don't forget to post your feedback here.

Regards
Shouvik

Hey,thanx Ur Code Was Great,but I Need To Enter Data Like country Name like india,america,australia etc Thru form1.the Next Time I Enter form2,i Should Get List Of Al The Countries.
& If I Delete Any Country Thru form1,it Should Reflect In Listbox Of form2.
I Need The Code Little Urently!!

HI karthik,

You can't Type data in Listbox use textbox along with a button to achieve this
then load the list box items in a table

on load event load the listbox with the table values

i already answered for deleting a record in your previous thread right
if you still fails and need code, contact me again...

with regards
VEnkatramasamy SN

No wat i meant was i entered the data like name of countries into DB table thru form1.
Now i need to display al the countries as listbox in form2.

Hi karthic,
Dispalying Table records in a list box is very siimple,
I assumned that
RS is your recordset
Country is the Field name
List1 is the listbox control name

Use the following code

rs.movefirst
   for i=0 to rs.recordcount
   listt1.AddItem (Rs!Country)
   RS.movenext
next

Try this and reply me

With regards
Venkatramasamy SN

Hey,thanx Ur Code Was Great,but I Need To Enter Data Like country Name like india,america,australia etc Thru form1.the Next Time I Enter form2,i Should Get List Of Al The Countries.
& If I Delete Any Country Thru form1,it Should Reflect In Listbox Of form2.
I Need The Code Little Urently!!

Thanks for the feedback.
Check this one too. I think you'll surely get from it what you want.

Best regards
Shouvik

hello karthik
with refence to your private msg, i am answering here because it may helpful to others too..

Even your question is clear,still your program logic is not clear...
clarify me these things...

1.you have data ina table
2.you are getting Id and location from the user in Form1(f1)
3.Displaying relevent records in form2

if it so the f2 combo will show you only one data that matches with the form1 values


else
1.you have some data in table
2.you need to add data from form1
3.you are displaying the data

if so...
write code for
1.Inserting form1 values to the table
2.then dispaly the data's from DB table

clarify these details

ya.u got it rite.user enters data thru form1 and combobox in form2 reflects that data.
My logic mite be a little bad as I am not familiar with DB syntax.

ok karthik,

First insert the Data in ti the table

insert into <tablename> values(text1.text,text2.text),conectionname

ya.u got it rite.user enters data thru form1 and combobox in form2 reflects that data.
My logic mite be a little bad as I am not familiar with DB syntax.

What about the code which I provided to you?
Have you seen it yet?
Make a visit to the code and you'll surely get your answer.

Hi Shouvik,
ur pgm is great.Tis is wat i wanted.Thanx a lot.
but pl clarify few things.


could u pl explain the syntax:

Set rsd = db.OpenRecordset("select cnt_name from
names where cnt_name='" & Trim(Text1.Text) & "'", dbOpenDynaset)

Here just tel me where are the places where we need to use & " '.
Sorry,i am not familar with DB syntax.

Hi Shouvik,
ur pgm is great.Tis is wat i wanted.Thanx a lot.
but pl clarify few things.


could u pl explain the syntax:

Set rsd = db.OpenRecordset("select cnt_name from
names where cnt_name='" & Trim(Text1.Text) & "'", dbOpenDynaset)

Here just tel me where are the places where we need to use & " '.
Sorry,i am not familar with DB syntax.

here rsd is just a recordset object. i've assumed that u r using DAO technique to make connection with the database. in case of DAO it is 'Recordset' but in case of ADO it is 'New Adodb.Recordset'.

recordset object is actually used to indicate a table or in other words it works as an pointer of the table. when we point a recordset to a table it adjusts itself with the table so that it can identify the BOF and EOF of the table to which it is pointed. in case of DAO we also require a database object in order to open the database before proceeding with any other task in relation with any tables presented in the database. you can also use a connection string to make connection in DAO but it is more easier to use a db object to create the connection.

this line dim db as database declares 'db' as a database object which can only recognize a DAO recordset.

this line set db=opendatabase(app.path & "\mydb.mdb") tells your program to create an active connection to the database specified in the paranthesis(here u have to specify the complete location of the db,this must be a physical path.if ur db is pwd protected u can also specify it here) and point the object 'db' to the database as an alias, so that u don't need to mention the long name within ur program any more, just specifying the 'db' will do the rest.

next u need to create the recordset object and point it to a particular table.remember that a recordset object can be pointed to a single table at a time.if u wish to point it to multiple tables u must close the current pointer and then u can point it to a diff. table.to close u can use rsd.close and followed by set rsd=nothing.these two lines unload current instance of the recordset object from the memory.
now to point the recordset to a specific table u use the openrecordset method.this line db.openrecordset tells ur program to open the table supplied as an arguement and make it available to the specified recordset object.this is done by set rsd.now in the arguement u can also pass sql statements which i've done here.now only specifying the table name is equivalent to the sql statement select * from <table name>.so when u use set rsd=db.openrecordset("<table name>"), u r actually passing the above sql statement.

&(ampersand) is used to concate strings.suppose u wish to extract information of that country whose name is "india".now if the value is static u can easily pass select * from country where cnt_name='india'.u must be familiar with that whenever u need to query on string values it must be supplied within single quotes.now imagine a situation where u don't know what value will be supplied to ur query as country name.this can be happen when u have a combo on ur form filled with country names and u let the end-user to select any value from it and clicking a button will fetch all associate details.so in this case u can't know which value will be passed to ur query string in advance.in such a situation u need to store the selected value in a variable and then pass the whole variable to the query as search criteria.u can pass a value to the query string but u can't pass a variable to it.so u have to join it with the query string.that's exactly what i've done here.i'm fetching the value from text1.text and joined it with the querystring.

so whenever u require to concate any outside string value to the sql query u need to pass '&' followed by the string that u wish to concate.now if u compare just like this :-

this is statement when the value of cnt_name is fixed in the query
select * from country where cnt_name='india'

this is the statement when the value is dynamic and can be passed from an outside variable
select * from country where cnt_name='" & trim(text1.text) & "'"
notice the red marked section in both the statements.this will show u the diff. clearly.

hope u will get some from the above lecture.
let me know if this helps you.

regards
Shouvik

hi Shouvik,
A personal thanx for ur patience with me.Tis is wat I wanted.I hav another doubt.I need to read data from an Xml file.Can I do tat using DAO??Or do I need to Use ADO only?Pl advise.I suppose u need to use some DOM
With regards,
Kartik

hi Shouvik,
A personal thanx for ur patience with me.Tis is wat I wanted.I hav another doubt.I need to read data from an Xml file.Can I do tat using DAO??Or do I need to Use ADO only?Pl advise.I suppose u need to use some DOM
With regards,
Kartik

well that's a separate issue.
if u've benefited from the above code then mark this thread as SOLVED.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.