DIGIT-ARC read-only archive · snapshot: July 23, 2026

need help in vb 6 programming

54 posts · originally from https://geek.digit.in/community/threads/need-help-in-vb-6-programming.176009/

R
rabjabber Original post #1
Jul 18, 2013 at 8:56 PM
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
S
Jul 19, 2013 at 10:11 PM
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
Shah #3
Jul 20, 2013 at 9:40 AM
Where did my post go?
krishnandu.sarkar
Jul 20, 2013 at 9:51 AM
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
R
Jul 20, 2013 at 6:34 PM
thanks guys

btw i made all my forms
R
Jul 22, 2013 at 2:51 PM
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 at 2:55 PM
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 :)
R
Jul 23, 2013 at 12:27 AM
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 at 7:45 AM
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
Shah #10
Jul 23, 2013 at 9:14 AM
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
Just post that part of code. I can help you with it.
R
rabjabber #11
Jul 23, 2013 at 10:07 AM
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 at 10:29 AM
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.
R
rabjabber #13
Jul 23, 2013 at 10:35 AM
if there are input filters in the database, how do i remove them?
krishnandu.sarkar
Jul 23, 2013 at 10:43 AM
Sorry didn't understand your query. What do you mean by Input Filter?
R
rabjabber #15
Jul 23, 2013 at 10:49 AM
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 at 11:11 AM
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)
R
rabjabber #17
Jul 23, 2013 at 11:43 AM
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 at 11:55 AM
^^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.
R
rabjabber #19
Jul 23, 2013 at 12:07 PM
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 at 12:58 PM
@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.
R
rabjabber #21
Jul 23, 2013 at 1:07 PM
no i didn't leave out the primary key
also i didn't program 2 fields for data
krishnandu.sarkar
Jul 23, 2013 at 1:18 PM
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.
R
rabjabber #23
Jul 23, 2013 at 3:42 PM
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 at 3:56 PM
Well without checking the program and database design it's hard to figure out. Did you tried googling for the same error?
R
rabjabber #25
Jul 23, 2013 at 5:06 PM
yeah i did and didn't understand any of that ****
krishnandu.sarkar
Jul 23, 2013 at 5:07 PM
Ok. Post your entire code here. And if possible a screenshot of Database Design too.
R
rabjabber #27
Jul 23, 2013 at 8:34 PM
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 at 9:54 PM
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"
End Sub

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

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)

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

thnx.....

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
R
rabjabber #29
Jul 23, 2013 at 11:53 PM
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



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)

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 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 at 7:31 AM
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,

Code:
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 :)
R
rabjabber #31
Jul 24, 2013 at 3:45 PM
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,

Code:
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
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 at 3:54 PM
Yeah right frame. Panel is what we call in .NET :p
R
rabjabber #33
Jul 24, 2013 at 4:27 PM
didn't work
it covered the buttons
krishnandu.sarkar
Jul 24, 2013 at 4:37 PM
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.
R
rabjabber #35
Jul 24, 2013 at 10:39 PM
thnx a lot guys
especially krishnandu.sarkar
R
rabjabber #37
Jul 27, 2013 at 2:55 AM
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 at 10:53 AM
The entire project is there in a folder. You need to copy that whole folder.
Z
Jul 28, 2013 at 4:06 AM
vb 2010 is much better than 6
R
rabjabber #40
Aug 20, 2013 at 8:51 PM
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

vb 2010 is much better than 6

that was uncalled for...................
but i know u're right
krishnandu.sarkar
Aug 20, 2013 at 9:31 PM
You have to search bro :p

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.
R
rabjabber #42
Aug 21, 2013 at 7:52 AM
never mind,
i did "save as" for every file into a different folder
R
rabjabber #43
Oct 7, 2013 at 7:01 PM
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 at 9:40 PM
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.
R
rabjabber #45
Oct 8, 2013 at 5:58 PM
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 at 6:03 PM
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?
R
rabjabber #47
Oct 8, 2013 at 6:17 PM
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
R
rabjabber #48
Oct 9, 2013 at 6:40 PM
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 at 9:11 PM
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 :)

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

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 :p So please google the appropriate Event do the steps mentioned above in that event :)
D
digik #50
Oct 9, 2013 at 9:49 PM
Can VB6 be installed in Windows7?
R
rabjabber #52
Oct 10, 2013 at 11:13 AM
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 :)



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 :p So please google the appropriate Event do the steps mentioned above in that event :)

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 at 11:48 AM
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 :p It's simple. I just said you the logic.
R
rabjabber #54
Dec 4, 2013 at 7:29 PM
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

Code:
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
Code:
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