To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Database Development

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Feb 24th, 2007, 07:29 PM   #1
lyilaly
Junior Member
 
Join Date: Feb 07
Posts: 26
lyilaly is an unknown quantity at this point (<10)
Resolved [RESOLVED] Accesing MSAccess database

Here´s another one:

I had this code on a excel page. Now i´m doing this page on VB6. How can i change the routines to access all the data from various tables i have in an access database. Assme that i have tables for all the selections to be made by the comboboxes also.

Code:
'=============
'Rig Selection
'=============
Private Sub text1_Change()
Text6.Text = Format(Now(), "MMM-DD-YYYY")
Do While Combo6.ListCount > 0
Combo6.RemoveItem (0)
Loop
Me.Combo6.AddItem "P-101"
Me.Combo6.AddItem "P-102"
Me.Combo6.AddItem "P-103"
Me.Combo6.AddItem "P-110"
Me.Combo6.AddItem "P-111"
Me.Combo6.AddItem "P-112"
End Sub

'=============
'Opcion "Pool"
'=============
Private Sub option1_Click()
Me.Text4.Text = 1
Me.Text5.Text = 1
End Sub

'===================
'Opcion "Vacaciones"
'===================
Private Sub option2_Click()
Me.Text4.Text = 2
Me.Text5.Text = 1
End Sub

'================
'Opcion "Vacante"
'================
Private Sub option3_Click()
Me.Text4.Text = 3
Me.Text5.Text = 1
End Sub

'================
'Tallas de Bragas
'================
Private Sub text3_Change()
Do While Combo1.ListCount > 0
Combo1.RemoveItem (0)
Loop
    Me.Combo1.AddItem "32"
    Me.Combo1.AddItem "34"
    Me.Combo1.AddItem "36"
    Me.Combo1.AddItem "38"
    Me.Combo1.AddItem "40"
    Me.Combo1.AddItem "42"
    Me.Combo1.AddItem "44"
    Me.Combo1.AddItem "46"
    Me.Combo1.AddItem "48"
    Me.Combo1.AddItem "50"
    Me.Combo1.AddItem "52"
    Me.Combo1.AddItem "54"
    Me.Combo1.AddItem "56"
    Me.Combo1.AddItem "N/A"
End Sub

'===============
'Tallas de Botas
'===============
Private Sub combo1_Change()
Do While Combo2.ListCount > 0
Combo2.RemoveItem (0)
Loop
    If Combo1.DataChanged = True Then
    '= "32" Or "34" Or "36" Or "38" Or "40" Or "42" Or "44" Or "46" Or "48" Or "50" Or "52" Or "54" Or "56" Then
        Me.Combo2.AddItem "35"
        Me.Combo2.AddItem "36"
        Me.Combo2.AddItem "37"
        Me.Combo2.AddItem "38"
        Me.Combo2.AddItem "39"
        Me.Combo2.AddItem "40"
        Me.Combo2.AddItem "41"
        Me.Combo2.AddItem "42"
        Me.Combo2.AddItem "43"
        Me.Combo2.AddItem "44"
        Me.Combo2.AddItem "45"
        Me.Combo2.AddItem "46"
        Me.Combo2.AddItem "N/A"
    End If
End Sub

'=============
'Tipo de Casco
'=============
Private Sub combo2_Change()
Do While Combo3.ListCount > 0
Combo3.RemoveItem (0)
Loop
    If Combo2.Text = "35" Or "36" Or "37" Or "38" Or "39" Or "40" Or "41" Or "42" Or "43" Or "44" Or "45" Or "46" Then
        Me.Combo3.AddItem "Verde Nuevo"
        Me.Combo3.AddItem "Verde Usado"
        Me.Combo3.AddItem "Blanco Nuevo"
        Me.Combo3.AddItem "Blanco Usado"
        Me.Combo3.AddItem "N/A"
    End If
End Sub

'==============
'Tipo de Lentes
'==============
Private Sub combo3_Change()
    Do While Combo4.ListCount > 0
            Combo4.RemoveItem (0)
    Loop
        If Combo3.Text = "Verde Nuevo" Or "Verde Usado" Or "Blanco Nuevo" Or "Blanco Usado" Or "N/A" Then
            Me.Combo4.AddItem "Claros"
            Me.Combo4.AddItem "Oscuros"
            Me.Combo4.AddItem "Ambos"
            Me.Combo4.AddItem "N/A"
        End If
End Sub

'==========
'Salvavidas
'==========
Private Sub combo4_Change()
    Do While Combo5.ListCount > 0
             Combo5.RemoveItem (0)
    Loop
        If combo4text = "Claros" Or "Oscuros" Or "Ambos" Or "N/A" Then
            Me.Combo5.AddItem "Nuevo"
            Me.Combo5.AddItem "Usado"
            Me.Combo5.AddItem "Pendiente"
            Me.Combo5.AddItem "N/A"
        End If
End Sub

'==============================
'Add data to the database sheet
'==============================
Private Sub Command1_Click()
    Dim lRow As Long
    Dim lPart As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Data")

    '============================
    'Locate first row on database
    '============================
    lRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row
  
    lPart = Me.Text1.Value
    'lPart = Me.text1.ListIndex
    
    '=======================
    'Check
    '=======================
    If Trim(Me.Text1.Value) = "" Then
        Me.Text1.SetFocus
        MsgBox "Please enter a part number"
Exit Sub
    End If
    '====================
    'Copy to the database
    '====================
        With ws
            .Cells(lRow, 1).Value = Me.Text1.Value
            .Cells(lRow, 2).Value = Me.Text2.Value
            .Cells(lRow, 3).Value = Me.Text3.Value
            .Cells(lRow, 4).Value = Me.Combo1.Value
            .Cells(lRow, 5).Value = Me.Cells(17, 10).Value
            .Cells(lRow, 6).Value = Me.Combo2.Value
            .Cells(lRow, 7).Value = Me.Cells(19, 10).Value
            .Cells(lRow, 8).Value = Me.Combo3.Value
            .Cells(lRow, 9).Value = Me.Combo4.Value
            .Cells(lRow, 10).Value = Me.Combo5.Value
            .Cells(lRow, 11).Value = Me.Combo6.Text
        End With
    
    '=============================
    'Clear data from txtbx & cbobx
    '=============================
        Me.Text1.Value = ""
        Me.Text2.Value = ""
        Me.Text3.Value = ""
        Me.Combo1.Value = ""
        Me.Combo2.Value = ""
        Me.Combo3.Value = ""
        Me.Combo4.Value = ""
        Me.Combo5.Value = ""
        Me.Combo6.Value = ""
        Me.Cells(17, 10).Value = ""
        Me.Cells(19, 10).Value = ""
End Sub

'=====================
'Command Button Clear
'=====================
Private Sub Command2_Click()
    Me.Text1.Text = ""
    Me.Text2.Text = ""
    Me.Text3.Text = ""
    Me.Combo1.Text = ""
    Me.Combo2.Text = ""
    Me.Combo3.Text = ""
    Me.Combo4.Text = ""
    Me.Combo5.Text = ""
    Me.Combo6.Text = ""
    Me.Text4.Text = ""
    Me.Text5.Text = ""
    Me.Text6.Text = ""
    Me.Option1.Value = False
    Me.Option2.Value = False
    Me.Option3.Value = False
    Me.Text1.SetFocus
End Sub

'=====================================================
'Command Button Borrar todo e ir a la pagina principal
'=====================================================
Private Sub Command3_Click()
    Me.Text1.Text = ""
    Me.Text2.Text = ""
    Me.Text3.Text = ""
    Me.Combo1.Text = ""
    Me.Combo2.Text = ""
    Me.Combo3.Text = ""
    Me.Combo4.Text = ""
    Me.Combo5.Text = ""
    Me.Combo6.Text = ""
    Me.Text4.Text = ""
    Me.Text5.Text = ""
    Me.Text6.Text = ""
    Me.Option1.Value = False
    Me.Option2.Value = False
    Me.Option3.Value = False
    Form2.Hide
    Form1.Show
End Sub
'====================================
thanks
lyilaly is offline   Reply With Quote
Old Feb 25th, 2007, 06:01 AM   #2
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,303
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
Re: Accesing MSAccess database

Create a recordset with an SQL SELECT query and load your combos from the results. Assuming you are using ADO code to connect to your database, and example would be
VB Code:
  1. Dim sSQL As String
  2. sSQL = "SELECT fieldname FROM tablename "
  3. Set rs = New ADODB.Recordset
  4. rs.Open sSQL, ConnectionObject
  5. Do While Not rs.EOF
  6.      Combo6.Additem rs.Fields.Item("fieldname").Value
  7.      rs.MovedNext
  8. Loop
  9. rs.Close
  10. Set rs = Nothing
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Feb 25th, 2007, 01:04 PM   #3
lyilaly
Junior Member
 
Join Date: Feb 07
Posts: 26
lyilaly is an unknown quantity at this point (<10)
Re: Accesing MSAccess database

Sorry,

But can you help me also with the ADO connection code? Don´t know how to.

Thanks
lyilaly is offline   Reply With Quote
Old Feb 25th, 2007, 01:15 PM   #4
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,107
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
Re: Accesing MSAccess database

Moved to Database Development forum

For an example, see the ADO Tutorial link in my signature.
si_the_geek is offline   Reply With Quote
Old Feb 25th, 2007, 07:38 PM   #5
lyilaly
Junior Member
 
Join Date: Feb 07
Posts: 26
lyilaly is an unknown quantity at this point (<10)
Re: Accesing MSAccess database

Thanks for you help....

Solved
lyilaly is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Database Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:59 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.