I recommend to you use a class to handle you second form For instance...
--Add a class to your vbproject and renamed as cls_Vehicle
--Add a form to you project and renamed as frmVehicle
--now add two text boxes, let's say txtCode and txtDes
--now add the following method to frmVehicle
sub configure(byval strCode as string,byval strDes as string,byval carId as long,byref curCon as adodb.connection)
txtCode=strCode
txtDes=strDes
m_carId=carId '//declare m_carId at declarations section on frmVehicle (private m_carId as integer)
set m_conn=curCon '//declare m_conn at declarations section on frmVehicle (private m_conn as new adodb.connection)
'//here you can put the code to populate a recordset and show the
'//related records from tbl_Vehicles according to m_carId on a list Box for example...
end sub
--now add some methods and properties to handle you form
--First add the following code in declaration section from your class file
private m_form as frmVehicle '//it will handle the form
private m_code as string '//to set car code on frmVehicle
private m_des as string '//to set description car on frmVehicle
private m_carId as long '//to save current Id Car
private m_con as adodb.connection '//to handle database operations
--Now you need add some properties like this
public property get carCode () as string
carCode =m_code
end property
public property let carCode(byval value as string)
=m_code=value
end property
--do the same for the m_des,m_carId and m_com fields as the code above
--Now Add to your class the following method
sub showForm
Set m_form = New frmVehicle
Load m_form
m_form.configure(m_code,m_des,m_carId)
m_form.Show 1
end sub
--Add a method to finalize you frmVehicle and free memory..
--something like this
sub shutdown()
if not m_form is nothing then
set m_form=nothing
end if
end sub
--You should declare this variable at form level (form1) and free when you close
--form1 to improve performance
private dlg as cls_Vehicle
--Now you can call you form2 (frmVehicle) from form1
--put the following code inside the event you want to call form2 (frmVehicle)
--usually is RowColChange event I mean for each row on your grid
if dlg is nothing then set dlg=new cls_vehicle
with dlg
.connection=myConn '//this sould be your current ADODB.connection object
.carCode=grd.Columns("Code").text
.cardescription=grd.Columns("description").text
.carId=grd.Columns("carID").text
.showForm '//this code will show your form as a dialog box
end with
--put the following code on unload event on form1
dlg.shutdown
--and finally on your command button on form2 (frmvehicle)
--add the following code
sub cmd_Click()
dim strQry as string
strQry="INSERT INTO tblVehicle(carId,name,des)" & _
"VALUES (" & m_carid & ",'" & txtCOde "'," & txtdes ")"
m_conn.execute strqry
unload me
end sub
*******************
DONE!
This approach allow to accomplish you request in a very elegant way...
and will be more easy maintain your application.
Hope this can help..!!
Good Look!