I am trying to make my first simple class project. I am not sure about using text files or a Database. I think using multiple text files or 1 really long one would get daunting as well as confusing for me. So, I think I want to stick to an Access database. However, my pc is a little older.. So I am sure it has an older version of it installed. It's just a simple classroom record kind of thing - (for now, if I continue with this class project or I move onto something else as a project). I did some pre-research but I'm not finding exactly what I am looking for. I would like it to call the information from each classroom. Hoping someone here can help me.
I see signitures, but I do not see a way for me to edit mine ATM. so,
Monroe High School.. GO HORNETS!
Last edited by Mongoose_MHS; May 17th, 2024 at 12:47 PM.
Reason: resolved
It would be helpful to know what it is that you are having trouble with. As it is, you've attached the project and what looks like a database, but what is working or is not working?
Well, I want it to connect to the Database and then when i press a button it calls the information from that classroom. I'm sorry, I am new and did some pre-research but I am not finding exactly what i want and I do not know how to piece it together. So, unfortunately I cannot give any example code(s) atm. I was hoping somebody could help me piece it together.
Since I have only 1 table.. Thinking select the "Classroom" per button and show that classroom information? I'm just trying to understand how each button does that.
what's the difference of "Option Explicit" & "Option Explicit On"? Are they not the same thing?
from google
Code:
When Option Explicit On or Option Explicit appears in a file, you must explicitly declare all variables by using the Dim or ReDim statements. If you try to use an undeclared variable name, an error occurs at compile time. The Option Explicit Off statement allows implicit declaration of variables
I'm not sure if i'm doing this right. If not, can someone please explain or show me what I am doing wrong? I think maybe I shouldn't be using the term "Classroom" too much in the same coding as I am already getting a little confused.
Code:
Option Explicit
Private Sub Form_Load()
db Connection
End Sub
Private Sub getClassrooms(strClassroom)
Dim rs As New Recordset
dbconnection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cnn
cmd.CommandText = "select Classroom, Students from Table1 where Classroom='" & strClassroom & "'"
Set rs = cmd.Execute
lblStudents.Caption = rs.RecordCount
'Boys
'Girls
'Bandmemers
'How do I get The other Counts tho?
End Sub
Private Sub Command1_Click()
'Show classroomroom 1 information
Classroom = "Classroom 1"
getClassrooms Classroom
End Sub
Private Sub Command2_Click()
Classroom = "Classroom 2"
getClassrooms Classroom
End Sub
Private Sub Command3_Click()
'Show classroom 3 information
Classroom = "Classroom 3"
getClassrooms Classroom
End Sub
Private Sub Command4_Click()
'Show classroom 4 information
Classroom = "Classroom 4"
getClassrooms Classroom
End Sub
Last edited by Mongoose_MHS; May 14th, 2024 at 03:27 PM.
There are others here that can do this in their sleep, so I hope they chime in.
In the mean-time, this connects to your database, and displays (via MsgBox) number of students in each class.
This should be enough to get you going.
Code:
Option Explicit 'you WANT this!!
Private Sub Command1_Click()
'Show classroomroom 1 information
End Sub
Private Sub Command2_Click()
'Show classroom 2 information
End Sub
Private Sub Command3_Click()
'Show classroom 3 information
End Sub
Private Sub Command4_Click()
'Show classroom 4 information
End Sub
Private Sub Form_Load()
'-------------------------------------------------------------------------------------------
' Connect to data source
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "User ID=Admin;password= ;" & " Data Source=" & App.Path & "\DB1.mdb;"
cn.CursorLocation = adUseClient
cn.Open
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Execute SQL queries etc.
Dim strSQL As String
strSQL = "SELECT Students " & _
"FROM Table1"
Dim rs As ADODB.Recordset
Set rs = cn.Execute(strSQL)
Do Until rs.EOF
MsgBox rs.Fields.Item("Students")
rs.MoveNext
Loop
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Clean-up
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
'-------------------------------------------------------------------------------------------
End Sub
Ty, however I find that more confusing as it is not working with the buttons I put there - (As I want it to work as it is designed). So, the message box thing isn't really helping me. Each button should be calling the info from the database. Ty anyways
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
Not sure why the DB/SQL experts aren't offering anything,
so I'll show how to populate your form fields from Command1 button.
I didn't use your Class Module
Probably better, and simpler ways, but...
Code:
Option Explicit 'you WANT this!!
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Form_Load()
'-------------------------------------------------------------------------------------------
' Connect to data source
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "User ID=Admin;password= ;" & " Data Source=" & App.Path & "\DB1.mdb;"
cn.CursorLocation = adUseClient
cn.Open
'-------------------------------------------------------------------------------------------
End Sub
Private Sub Form_Unload(Cancel As Integer)
'-------------------------------------------------------------------------------------------
' Clean-up
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
'-------------------------------------------------------------------------------------------
End Sub
Private Sub Command1_Click()
'Show classroomroom 1 information
'-------------------------------------------------------------------------------------------
' Execute SQL queries etc.
Dim strSQL As String
strSQL = "SELECT * " & _
"FROM Table1 " & _
"WHERE Classroom = '1' "
Set rs = cn.Execute(strSQL)
lblClassroom = rs.Fields.Item("Classroom")
lblStudents = rs.Fields.Item("Students")
lblBoys = rs.Fields.Item("Boys")
lblGirls = rs.Fields.Item("Girls")
Label6 = rs.Fields.Item("Bandmemers")
'-------------------------------------------------------------------------------------------
End Sub
Private Sub Command2_Click()
'Show classroomroom 2 information
End Sub
Private Sub Command3_Click()
'Show classroomroom 3 information
End Sub
Private Sub Command4_Click()
'Show classroomroom 4 information
End Sub
Well, I am not sure if you are trying to do something with a VB6 CLASS or just something with CLASSRooms.
If the latter, I took your project and simplified it.
I used an array of Command Buttons and a 'regular' Module. I also changed all your TEXT fields to NUMERIC fields in your DB, and renamed Bandmemers to BandMembers.
I also renamed label6.
EDIT: But I did not do the cleanup as mms showed you.
Ok, I will look at it in a bit. I have an appointment to go to.
EDIT: I checked real quick.. very nice! TY! Would this work with menus as well? I'm starting to get into the "Menu" things lately because of the other thread on menu icons lol..
Last edited by Mongoose_MHS; May 15th, 2024 at 04:40 PM.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
I'm so excited as of this afternoon! My school is considering making school sports cards. We have baseball, basketball, volleyball, band just to name a few things we have. So, I definately want to make something nice and far more advanced than the above project. Ok, I know this isn't my first class project. I didn't know if I should start a new topic or not..
I probably will as the above project is not really the same thing. Sorta, still reading / writing to and from a DB. I don't know where to begin, well I guess design aspect so the info fits right or start playing around with DB to see how it should play out - I don't know. I'll figure it out.. This project "could" be someting to help the Athletic Director on his PC. Anyways, I'm just so excited! I have a few ideas I want to pitch to them.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
OI.. I can already see that I need fafalone's help again.. So, I added a new submenu ABOVE all the others - basicaly FILE/EXIT and the checkmarks aren't working right now
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
This is what I have so far.. So, maybe fafalone can help me fix the menu checkboxes since I added ABOVE the original submenus that is throwing it off.. Please and thank you fafalone.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
Ohhhh.. I would like to put an animated hornet flying randomly on the main form.. That would be cool as hell.. I'll have to look into that. Doesn't have to be animated, just flying around.. It would be cool tho!
Last edited by Mongoose_MHS; May 22nd, 2024 at 06:31 PM.
Reason: spelling
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
This is what I have so far.. So, maybe fafalone can help me fix the menu checkboxes since I added ABOVE the original submenus that is throwing it off.. Please and thank you fafalone.
If you insert something at position 0, the original is pushed to position 1. There's no magic IDs here, no secret settings. It's just the numerical order they appear in, starting the count from 0. You moved top menu over, so now instead of hSubmenu = GetSubMenu(hMenu, 0), you want hSubmenu = GetSubMenu(hMenu, 1) in both Check and Uncheck subs.
Thank you, works fine so far that I know of. If any issues arrise I'll ask.
Code:
Public Sub CheckItemByIndex(n As Long)
Dim hMenu As LongPtr
Dim hSubmenu As LongPtr
hMenu = GetMenu(Me.hWnd)
hSubmenu = GetSubMenu(hMenu, 1) 'ADJUSTED
CheckMenuItem hSubmenu, n, MF_BYPOSITION Or MF_CHECKED
End Sub
Public Sub UncheckItemByIndex(n As Long)
Dim hMenu As LongPtr
Dim hSubmenu As LongPtr
hMenu = GetMenu(Me.hWnd)
hSubmenu = GetSubMenu(hMenu, 1) 'ADJUSTED
CheckMenuItem hSubmenu, n, MF_BYPOSITION Or MF_UNCHECKED
End Sub
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
I know this probably isn't new to you guys that's been here for awhile.. This is awesome! I know I haven't accomplished much yet.. However, I am amazed at how this is going so far! Thank you. I hope they take it under consideration as a new tool. Who knows?
Last edited by Mongoose_MHS; May 22nd, 2024 at 08:58 PM.
Reason: spelling
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
VB6 used to be a very popular introductory programming language; it was designed to be simple for beginners and non-programmers to be able to rapidly make useful small applications. Some key features and books by some brilliant people in later versions also opened the door to large, advanced, complex programs and drop in components/code non-experts could use.
VB.NET has a much steeper learning curve; it's a 'for professional programmers' language. That's how Microsoft lost their near-complete domination they enjoyed with VB5-6; with the equally easy and better cross-platform Java and Python, Windows-only .NET (at first) wasn't as appealing, and people were absolutely *furious* Microsoft was telling them 'screw all your existing apps and code, we're abandoning the most popular language in the world to shove this new shiny down your throat even though it's completely incompatible so start rewriting!'.
VB6 is really showing its age now, but there still remains a lot of businesses using VB6 apps and components, and of course VBA is the same language. But IMO it still fills one niche like nothing else: combining rapid GUI development and simplicity with easily accessible low level power; all the new stuff takes you one direction or the other, making the other difficult to impossible within the same language.
The best hope for the language to reverse course and regain some popularity is twinBASIC, the answer to the question 'What might the VB6 language look like today had it never been abandoned?' It's got a modern editor, full backwards compatibility (minus bugs and a few unimplemented features as it's still in beta under development), and dozens of new language features VB6 programmers have been wished for going back decades like 64bit. So if you like VB6 but want some more modern; it's worth looking at.
I am using an old PC that was given to me a little while back with vb 6 installed with no cd's so I do not have the MSDN parts.. So I can only use what I have available.. I still think this is pretty cool that I can create my own applications. I don't know if I can install it on my new PC yet.. I'll have to look into that.
Thank you for helping me out with this menu thing, I find it pretty cool so far!
Last edited by Mongoose_MHS; May 22nd, 2024 at 11:10 PM.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
You can install VB6 on the newest PCs with Windows 10 and 11, but make sure to search for instructions because you have to take some extra steps vs just running setup.
tB of course is designed for newer systems and actually can't be run on Windows XP or earlier (though programs compiled in it will run on xp, and soon 2000, but not 98/95/nt4 or earlier).
Windows 11 is a major downgrade. More ads and bloat, god awful UI changes, now they're sticking "AI" everywhere, more telemetry and phoning home...
Windows 10 IoT Enterprise LTSC is not only the best version of Windows 10 by a long shot, but unlike consumer versions it will continue to receive security updates through 2032. So that's the earliest I'll begin to consider switching, hopefully to a less awful Windows 12, but I'm not holding my breath.
But you can install VB6 (and tB if you ever check it out) on both with the same procedure. Most people here are using on 10/11 now already; you're the first person I've heard of still using XP in quite a while now, even Win7 is getting rare.
I just came up with an issue maybe you help with on the menu? So, when I click a subsubmenu, I can't fill out a label in form 2 with different elements.. Thinking maybe some "IF" statements need to be put in? I have notes in the code, you'll see the note on form1 when I click the first subsubmenu.
Code:
Private Sub mnuSubSubMenu_Click(Index As Integer) 'Unique.. No number, do the same below
Dim c As Long
For c = 0 To mnuSubSubMenu.UBound
mnuSubSubMenu(c).Checked = (Index = c)
Form2.mnuSubSubMenu(c).Checked = mnuSubSubMenu(c).Checked
'Noticing an issue here.. I can't fill the label on form 2 with different things. Maybe "IF" statements needed?
Form2.Label1.Caption = "Division: Jr. Hornets Basketball Team"
'What if I decided to click on "Senior Hornets Basketball Team instead of the Jr. Hornets Basketball team"?
Next
Unload Me
Load Form2
Form2.CheckItemByIndex 0
Form2.Show vbModal
End Sub
Last edited by Mongoose_MHS; May 23rd, 2024 at 01:31 PM.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
What I don't like is it puts the underline mark of the first letter in the caption.. Is there something we can put in this line of code so it won't put that underline?
What do you mean it didn't work? It's setting the caption fine for me.
If you don't understand basic If statements you'll learn a lot quicker if you read some introductory tutorials or books rather than go right to trying to make something from scratch,
Code:
Private Sub mnuSubSubMenu_Click(Index As Integer) 'Unique.. No number, do the same below
Dim c As Long
For c = 0 To mnuSubSubMenu.UBound
mnuSubSubMenu(c).Checked = (Index = c)
Form2.mnuSubSubMenu(c).Checked = mnuSubSubMenu(c).Checked
Next
Unload Me
Load Form2
If Index = 0 Then
Form2.Label1.Caption = "Division: Jr. Hornets Basketball Team"
ElseIf Index = 1 Then
Form2.Label1.Caption = "Division: Sr. Hornets Basketball Team"
End If
Form2.CheckItemByIndex 0
Form2.Show vbModal
End Sub
What do you mean it didn't work? It's setting the caption fine for me.
If you don't understand basic If statements you'll learn a lot quicker if you read some introductory tutorials or books rather than go right to trying to make something from scratch,
Code:
Private Sub mnuSubSubMenu_Click(Index As Integer) 'Unique.. No number, do the same below
Dim c As Long
For c = 0 To mnuSubSubMenu.UBound
mnuSubSubMenu(c).Checked = (Index = c)
Form2.mnuSubSubMenu(c).Checked = mnuSubSubMenu(c).Checked
Next
Unload Me
Load Form2
If Index = 0 Then
Form2.Label1.Caption = "Division: Jr. Hornets Basketball Team"
ElseIf Index = 1 Then
Form2.Label1.Caption = "Division: Sr. Hornets Basketball Team"
End If
Form2.CheckItemByIndex 0
Form2.Show vbModal
End Sub
I got it to work, it's just putting the UNDERLINE of the first letter of the subsubmenu caption.. I don't want that underline there.. See #34 picture
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
I got it to work. Thank you! I knew there had to be an "IF" statement somewhere.. hoping to do it without one..
Code:
Private Sub mnuSubSubMenu_Click(Index As Integer) 'Unique.. No number, do the same below
Dim c As Long
For c = 0 To mnuSubSubMenu.UBound
mnuSubSubMenu(c).Checked = (Index = c)
Form2.mnuSubSubMenu(c).Checked = mnuSubSubMenu(c).Checked
'I wanted to do it here without "IF" statements.. However it didn't work.
Next
Unload Me
Load Form2
'So, We had to rely on this:
If Index = 0 Then
Form2.Label1.Caption = "Division: Jr. Hornets Basketball Team"
ElseIf Index = 1 Then
Form2.Label1.Caption = "Division: Sr. Hornets Basketball Team"
End If
Form2.CheckItemByIndex 0
Form2.Show vbModal
End Sub
Last edited by Mongoose_MHS; May 23rd, 2024 at 03:00 PM.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that
Ok, I'm not trying to sound like a jerk here.. However, whoever created the flexgrid needs to be smacked across the back of their head really hard! Why is there no default feature in the settings to make each HEADER and column info LEFT, CENTER, Right?
I should be able to pick any HEADER and say CENTER. I should be able to pick if the info in that row will be LEFT, CENTER or RIGHT.. So, as I sit here and put a grid on the form, I can fill in the HEADERS but not design it to my specific needs... I can say vertical, horizontal scrollsbars, how many columns, how many rows.. Like they didn't fully think this thing out.
Question: Is there a flexgrid creator app out out there where I can create a custom flexgrid? If not, Maybe someone could create one?
Last edited by Mongoose_MHS; May 24th, 2024 at 07:26 PM.
Monroe High School.. GO HORNETS!
If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that