# need help in vb 6 programming



## rabjabber (Jul 18, 2013)

so there is this school project i am developing
i made a mistake and started and completed all the form in vb 10. and then my teacher told me that i require to redo the project in vb6, so i was wondering if there is any way to copy all the forms from vb 10 to vb 6 as it is


----------



## Santa Maria! (Jul 19, 2013)

I doubt it. Visual Basic went through a MASSIVE change after VB6. It became VB.NET and runs in the .NET environment. They are  considered different languages now. 
Best start with the manual labour.


----------



## Shah (Jul 20, 2013)

Where did my post go?


----------



## krishnandu.sarkar (Jul 20, 2013)

Shah said:


> Where did my post go?



Few posts got deleted while the last maintenance was going on.

*www.thinkdigit.com/forum/feedback/161164-tdf-upgraded-post-bugs-here-please-33.html

@OP No Forms from VB10 can't be imported to VB6 AFAIK


----------



## rabjabber (Jul 20, 2013)

thanks guys

btw i made all my forms


----------



## rabjabber (Jul 22, 2013)

guys, i need more help.
so i connected all the screens, made all the databases in MS access and connected them to the respective adodc's 
now 4 out of 5 have to be connected to datagrids which i already did.
but the last one has to add data to a database. which i have no clue how to do??
can you tell me the steps to be followed to input some data in textboxes click a button and take all that data to a database made in ms access and connected to a adodc on that form?


----------



## krishnandu.sarkar (Jul 22, 2013)

Visual Basic Tutorial Lesson 25:Creating VB database applications using ADO control

adding record to the database using adodc in vb6 | DaniWeb

VB6 Using ADO Data Control

Hope that helps


----------



## rabjabber (Jul 23, 2013)

that helped to some extent. i tried with just one textbox giving data to one field in a table with multiple feilds. worked like a charm

but when i coded for all the fields it gave me the following error
run-time error '-2147217887 (80040e21)':
multi-step operation generated errors. check each status value



btw i'm using office 2010 and vb6


----------



## krishnandu.sarkar (Jul 23, 2013)

That runtime error generally means type mismatch. Checkout the values you are passing to the fields.

Checkout run-time error (80040e21) Multiple-step OLE DB-VBForums and Answer : what is "Multiple-step operation generated errors" Run-time error (80040e21) ?


----------



## Shah (Jul 23, 2013)

rabjabber said:


> that helped to some extent. i tried with just one textbox giving data to one field in a table with multiple feilds. worked like a charm
> 
> but* when i coded for all the fields* it gave me the following error
> run-time error '-2147217887 (80040e21)':
> ...


Just post that part of code. I can help you with it.


----------



## rabjabber (Jul 23, 2013)

Shah said:


> Just post that part of code. I can help you with it.



Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Staff_Name") = Text1.Text
Adodc1.Recordset.Fields("Staff_ID") = Text2.Text
Adodc1.Recordset.Fields("Age") = Text3.Text
Adodc1.Recordset.Fields("Address") = Text4.Text
Adodc1.Recordset.Fields("DOB") = Text6.Text
Adodc1.Recordset.Fields("Father's Name") = Text7.Text
Adodc1.Recordset.Fields("Education/Qualification") = Text8.Text
Adodc1.Recordset.Fields("Job Description") = Text9.Text
Adodc1.Recordset.Fields("Date of Joining") = Text10.Text
Adodc1.Recordset.Fields("initial salary") = Text11.Text
Adodc1.Recordset.Fields("Contact no") = Text12.Text
Adodc1.Recordset.Fields("2nd Contact") = Text13.Text
Adodc1.Recordset.Update


----------



## krishnandu.sarkar (Jul 23, 2013)

Ok two things that comes into my mind is, I guess you need to use Adodc1.Recordset.Fields("Staff_Name").Value = Text1.Text

Another thing I notice is Staff_ID, Age, Date of Joining, initial salary etc. may be int / DateTime in your database. So please check that. You need to cast the values according to that. Otherwise you'll get runtime error.

Also never name database fields with space, it creates problem sometimes, generally use _ instead of space.


----------



## rabjabber (Jul 23, 2013)

if there are input filters in the database, how do i remove them?


----------



## krishnandu.sarkar (Jul 23, 2013)

Sorry didn't understand your query. What do you mean by Input Filter?


----------



## rabjabber (Jul 23, 2013)

krishnandu.sarkar said:


> Ok two things that comes into my mind is, I guess you need to use Adodc1.Recordset.Fields("Staff_Name").Value = Text1.Text
> 
> Another thing I notice is *Staff_ID, Age, Date of Joining, initial salary etc. may be int / DateTime* in your database. So please check that. You need to cast the values according to that. Otherwise you'll get runtime error.
> 
> Also never name database fields with space, it creates problem sometimes, generally use _ instead of space.



that is what i meant by input filters





anyways doesn't matter coz i tried your solutions. didn't work
thnx for your time though


----------



## krishnandu.sarkar (Jul 23, 2013)

Those are field type, you need to set some field type. It's not possible to set no field type for a field.

But to get your existing code going, you can set them as Varchar (Text in Access)


----------



## rabjabber (Jul 23, 2013)

that's what i did

i got past that error by redoing my database 
but now it's giving a different error


run-time error '-2147217904 (80040e10)':
[Microsoft][ODBC Microsoft Access Driver] COUNT field incorrect


----------



## krishnandu.sarkar (Jul 23, 2013)

^^You mean by converting those fields to Text, your code worked right?

Anyway, the last runtime means you are missing some field. I mean may be you are not passing value for some NOT NULL Field.


----------



## rabjabber (Jul 23, 2013)

but the code worked just fine with just one field
and is not working if i leave 3 - 4 fields


----------



## krishnandu.sarkar (Jul 23, 2013)

@rabjabber Bro, may be the fields in database are NOT NULL fields, it means the fields cannot have NULL Value i.e. no value at all. So while inserting you have to provide values for them.

OR you need to declare those fields as NULL Fields, means those fields can have NULL value.

And you said that your code worked with one fields and not working when you are leaving 3 - 4 fields blank. Are you sure, you are not leaving the Primary Key field?

May be your database have all the fields set to NULL, but you were inserting Primary Key field that time. But now on your code may be you are not inserting Primary Key field. Primary Key fields cannot be NULL at all.

Hope you get what I mean.


----------



## rabjabber (Jul 23, 2013)

no i didn't leave out the primary key
also i didn't program 2 fields for data


----------



## krishnandu.sarkar (Jul 23, 2013)

Ok, then there is another possibility which can say COUNT field incorrect is, the SQL query that you are building.

But the basic rule remains same. Try to learn debugging by the message you are getting. COUNT Field Incorrect means the No of Fields you are passing, the basic problem lies there.

Anyway, I think it's problem with the SQL Query. May be some field contains ' character and that's what creating the problem but ending the quote for the SQL String.

If you have any ' in any of the text field try Sanitizing it, you can try Replace method to do that. Replace ' with '' (Note that it's 2 single ' char not the " double one).

Anyway, in programming terms it's called escape sequence.

BTW your code may only be fine for Insert, for Update and all you need to use Adodc1.Recordset.Edit AFAIK.


----------



## rabjabber (Jul 23, 2013)

i don't entirely get what you are trying to say but i know that there is no ' in any of the field names or records or anywhere

can some thing else cause this problem

i'm trying the hit and try method
i omit a piece and then see if it works

so far i know 6 fields that are not causing the problem


----------



## krishnandu.sarkar (Jul 23, 2013)

Well without checking the program and database design it's hard to figure out. Did you tried googling for the same error?


----------



## rabjabber (Jul 23, 2013)

yeah i did and didn't understand any of that ****


----------



## krishnandu.sarkar (Jul 23, 2013)

Ok. Post your entire code here. And if possible a screenshot of Database Design too.


----------



## rabjabber (Jul 23, 2013)

don't worry, solved

now that leaves me with two more problems. i use the following code to keepa check that the data entered is numeric

Private Sub Text2_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii = 127 Or KeyAscii = 8)) Then MsgBox "please enter valid characters"
End Sub


it works just fine but after displaying the msgbox, it still enters the value


the second problem :-

there are 4 radiobuttons on one form 2 for gender and 2 for some other **** that i forgot (maybe marital status) but while the program is running, i can only select one of them. can you tell me the code to be able to select two of them (1 for each)

and also how to get the input from those radio buttons to the database

thnx.....


----------



## krishnandu.sarkar (Jul 23, 2013)

rabjabber said:


> don't worry, solved



Care to share what was the problem and how you solved it? It's just for incase anyone looking for the same problem will get the answer



> now that leaves me with two more problems. i use the following code to keepa check that the data entered is numeric
> 
> Private Sub Text2_KeyPress(KeyAscii As Integer)
> If Not ((KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii = 127 Or KeyAscii = 8)) Then MsgBox "please enter valid characters"
> ...



LOL..!! I used to code in VB6 around 3 years ago. I guess, Keypress event passes something like KeyPressEvent Object or something like that

So it'll be much like e.KeyCode > 47 and so on... And to actually stop that e.Keypress = false.

But I'm not sure whether this exists in VB6.

If not, you can use it as function like if KeyAscii is within your range return true else return false and based on that clear the Textbox by Textbox.Text = "" (i.e. making it blank)



> the second problem :-
> 
> there are 4 radiobuttons on one form 2 for gender and 2 for some other **** that i forgot (maybe marital status) but while the program is running, i can only select one of them. can you tell me the code to be able to select two of them (1 for each)
> 
> ...



Yeah by default, all the Radio Buttons in a form is treated as single group. You can set Group Properties in Radio Buttons, that will do. Otherwise you can use Panel and then place Radio Buttons to that panel to group them.

Mean insert a panel from toolbox and place Male / Female Radio Buttons on that and insert another panel and place Married / Unmarried radio buttons on that.

Otherwise check if Group Property is there (It's there in VB.NET I guess, not sure about VB6), if it's present them set Gender as group to Male / Female RB and Martial_Status on Married / Unmarried RB


----------



## rabjabber (Jul 23, 2013)

krishnandu.sarkar said:


> Care to share what was the problem and how you solved it? It's just for incase anyone looking for the same problem will get the answer



idk how i solved it
i just deleted all my databases made them again with simpler field names and all data types set to text and then re inserted the code





krishnandu.sarkar said:


> LOL..!! I used to code in VB6 around 3 years ago. I guess, Keypress event passes something like KeyPressEvent Object or something like that
> 
> So it'll be much like e.KeyCode > 47 and so on... And to actually stop that e.Keypress = false.
> 
> ...



do u mean that i should declare a variable and then make it true if my IF......THEN condition is satisfied and if the variable is true then clear the textbox?





krishnandu.sarkar said:


> Yeah by default, all the Radio Buttons in a form is treated as single group. You can set Group Properties in Radio Buttons, that will do. Otherwise you can use Panel and then place Radio Buttons to that panel to group them.
> 
> Mean insert a panel from toolbox and place Male / Female Radio Buttons on that and insert another panel and place Married / Unmarried radio buttons on that.
> 
> Otherwise check if Group Property is there (It's there in VB.NET I guess, not sure about VB6), if it's present them set Gender as group to Male / Female RB and Martial_Status on Married / Unmarried RB



thnx............. i'll check and let u know


----------



## krishnandu.sarkar (Jul 24, 2013)

rabjabber said:


> idk how i solved it
> i just deleted all my databases made them again with simpler field names and all data types set to text and then re inserted the code



Got it, it was problem with the Field Names. Don't use space in field names as I said above in the beginning, it was creating problem while building the query (which takes place in the background).



> do u mean that i should declare a variable and then make it true if my IF......THEN condition is satisfied and if the variable is true then clear the textbox?



Yeah, I meant that.

But you don't need to, as I was much accustomed with VB.NET now, I forgot in VB6 the it used to be KeyAscii = 0. This makes setting the KeyPress ASCII to be 0 and insert nothing.

So,


```
Private Sub Text2_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii = 127 Or KeyAscii = 8)) Then 
    MsgBox "please enter valid characters"
    KeyAscii = 0 'Prevents Input
End Sub
```



> thnx............. i'll check and let u know



Sure


----------



## rabjabber (Jul 24, 2013)

krishnandu.sarkar said:


> But you don't need to, as I was much accustomed with VB.NET now, I forgot in VB6 the it used to be KeyAscii = 0. This makes setting the KeyPress ASCII to be 0 and insert nothing.
> 
> So,
> 
> ...


thanx worked like a charm

by panel do u mean frame??
coz that didn't work
i don't even know what frames are for


----------



## krishnandu.sarkar (Jul 24, 2013)

Yeah right frame. Panel is what we call in .NET


----------



## rabjabber (Jul 24, 2013)

didn't work
it covered the buttons


----------



## krishnandu.sarkar (Jul 24, 2013)

Bro, you need to place it right way, and then you need to use "Send It To Back" and place the Radio Buttons on it.


----------



## rabjabber (Jul 24, 2013)

thnx a lot guys 
especially krishnandu.sarkar


----------



## krishnandu.sarkar (Jul 25, 2013)

Glad that it helped.


----------



## rabjabber (Jul 27, 2013)

one more thing..........

if i want to store a copy of the entire project in, say a pen drive, do i 'save forms as' and then the project in another folder and then copy it to the pen drive or is there an easier method


----------



## krishnandu.sarkar (Jul 27, 2013)

The entire project is there in a folder. You need to copy that whole folder.


----------



## zeeshanaayan07 (Jul 28, 2013)

vb 2010 is much better than 6


----------



## rabjabber (Aug 20, 2013)

guys, 
after all this time i didn't touch my work at all and now i need to back it up but couldn't find any form or project files in the folder



zeeshanaayan07 said:


> vb 2010 is much better than 6



that was uncalled for................... 
but i know u're right


----------



## krishnandu.sarkar (Aug 20, 2013)

You have to search bro 

One Trick : Open VB > Go To Files > Recent Projects. Check if it opens and runs fine, if yes go to the folder and take a backup.

Else you may have already moved the whole project to anywhere else.


----------



## rabjabber (Aug 21, 2013)

never mind,
i did "save as" for every file into a different folder


----------



## rabjabber (Oct 7, 2013)

rabjabber said:


> never mind,
> i did "save as" for every file into a different folder



after that the problem is that even if i have to make a small modification i have to save as in that folder 
is there a way i can make the new folder the "working" folder of vb6
i did the "open in" thing and it is opening in the new folder but not saving........


----------



## krishnandu.sarkar (Oct 7, 2013)

Did you opened it as Project? If you are opening every form as a file you need to do that, if you open the whole thing as a project, you don't need to. As VB maintains .project / .prj file for that.


----------



## rabjabber (Oct 8, 2013)

krishnandu.sarkar said:


> Did you opened it as Project? If you are opening every form as a file you need to do that, if you open the whole thing as a project, you don't need to. As VB maintains .project / .prj file for that.



by open in  i mean that the shortcut starts in the new folder

btw i'm opening the whole thing as a project but in the folder /program files(x86)/ visual studio/.............../VB98 there is no .frm or .proj file..........
when i opent it through vb it is there but when i open it in windows explorer it's not, also i tried copying a frm file from the vb window to my desktop it gives the file not found error


----------



## krishnandu.sarkar (Oct 8, 2013)

rabjabber said:


> by open in  i mean that the shortcut starts in the new folder
> 
> btw i'm opening the whole thing as a project but in the folder /program files(x86)/ visual studio/.............../VB98 there is no .frm or .proj file..........
> when i opent it through vb it is there but when i open it in windows explorer it's not, also i tried copying a frm file from the vb window to my desktop it gives the file not found error



I didn't understand. You open VB from start menu right? Then how are you opening the project? From Recent Projects menu? Or by clicking on File > Open?


----------



## rabjabber (Oct 8, 2013)

krishnandu.sarkar said:


> I didn't understand. You open VB from start menu right? Then how are you opening the project? From Recent Projects menu? Or by clicking on File > Open?



recent projects,        but both of them seem to work

so,       the project is visible just to vb


----------



## rabjabber (Oct 9, 2013)

guys help?


another problem


there is a datagrid on form1 and  adodc1 form2. on form2 there are textboxes whose datasource is adodc1 and datafields are also specified for each textbox.

what i want is that whichever record the user selects in the datagrid on form one should be displayed on the textboxes on the form2 textboxes


----------



## krishnandu.sarkar (Oct 9, 2013)

rabjabber said:


> recent projects,        but both of them seem to work
> 
> so,       the project is visible just to vb



Ye, that's one of the problem. I'll try to explain all of them...

1. As you are using Recent Projects to open your project, it uses the previous path for the project. And when you change the project folder's path, it's creating problem.
2. Yes .prj / .project files are VB specific, if you want to see those files you need to enable "Show Extension for Recognized Files" on Folder Options depending on the OS you use.
3. I guess you are using Win Vista / Win 7 / Win 8. In any of the cases, you need to open VB6 as "Run as Administrator", as your project file is under Program Files, OS above Win XP doesn't get native rights to write to that folder. And that's why you are facing the problem of saving each of the form in that way (as you said above). Open VB6 as Run as Administrator and your this problem will be solved.

Else copy the project folder to somewhere else (Other than C), and try to open the project in VB from File > Open. Again start VB as Run as Administrator.

Hope that helps. Let me know 



rabjabber said:


> guys help?
> 
> 
> another problem
> ...



Ok, this is specific to programming, I'll try to jot down the steps here...

1. Declare a public variable in Form2.
2. Now whenever someone selects something in Data Grid, set the public variable of Form2 to the ID of the selected Row and open Form2.

That's it 

NOTE : I used VB6 around 3 years ago, so I'm not sure which event occurs while selecting rows in Datagrid in VB  So please google the appropriate Event do the steps mentioned above in that event


----------



## digik (Oct 9, 2013)

Can VB6 be installed in Windows7?


----------



## krishnandu.sarkar (Oct 10, 2013)

^^Yes.


----------



## rabjabber (Oct 10, 2013)

krishnandu.sarkar said:


> Ye, that's one of the problem. I'll try to explain all of them...
> 
> 1. As you are using Recent Projects to open your project, it uses the previous path for the project. And when you change the project folder's path, it's creating problem.
> 2. Yes .prj / .project files are VB specific, if you want to see those files you need to enable "Show Extension for Recognized Files" on Folder Options depending on the OS you use.
> ...



thanks for the reply but i don't think you get any of my problems...........

first of all the project file and the form file are not visible in the windows explorer........ but they are visible from the vb pop up boxes of existing project and file>open...  so i did save as for each form in D drive and now they are visible.

second i know that is what i have to do but i don't know the syntax and the commands for making that specific record visible in the textboxes because by default the last navigated record is selected so what is the property of adodc that selects the records to display


----------



## krishnandu.sarkar (Oct 10, 2013)

rabjabber said:


> thanks for the reply but i don't think you get any of my problems...........
> 
> first of all the project file and the form file are not visible in the windows explorer........ but they are visible from the vb pop up boxes of existing project and file>open...  so i did save as for each form in D drive and now they are visible.



Ohh sorry, I have no idea too 



> second i know that is what i have to do but i don't know the syntax and the commands for making that specific record visible in the textboxes because by default the last navigated record is selected so what is the property of adodc that selects the records to display



Well, you need to learn VB bro. Learn or google it  It's simple. I just said you the logic.


----------



## rabjabber (Dec 4, 2013)

guys,
i'm using the following code to display a record i double click on (in the datagrid) to display it onto the other form


```
Private Sub DataGrid1_DblClick()
Load viewstaff
    viewstaff.Adodc1.Recordset.MoveFirst
    viewstaff.Adodc1.Recordset.Find "ID = " & _
       Adostaff.Recordset.Fields("ID").Value & "", , , 0
    viewstaff.Show
End Sub
```

it shows runtime error 3001 
arguements are of wrong types, are out of acceptable range or are in conflict with each other
after clicking debug it highlights

```
Private Sub DataGrid1_DblClick()
Load viewstaff
    viewstaff.Adodc1.Recordset.MoveFirst
    [U][I][B]viewstaff.Adodc1.Recordset.Find "ID = " & _
       Adostaff.Recordset.Fields("ID").Value & "", , , 0[/B][/I][/U]
    viewstaff.Show
End Sub
```

datagrid1 and adodc1 are on one form called staff
adodc1 is linked to an access database table called staff and has a field ID (yes, in caps)
the


----------

