adding a second database

citizen_cow
04-15-2004, 03:04 PM
Hi all. Love teh new layout. Very FRESH.

I created this program with the help of everyone here and now have a need to create a 2nd database for the same program.

It conisists of tabs and 2 combo boxes.

first tab is a combo where you enter a number, that tab and the next tab populate with the corresponding info.

Im trying to add a third tab with the same function, different info. Im having trouble adding in a second access db into the same code. Any direction.

The code as it is now is attached.

As it is now. The "TECH" is the cbo
http://spinningbus.com/vb/view1.jpg
http://spinningbus.com/vb/view2.jpg

the one I want to add to pull from a seperate database
"INITIALS" is the cbo...
http://spinningbus.com/vb/view3.jpg

Dim MouseX, MouseY

Dim db As Database
Dim rs As Recordset
Dim strslq As String
Option Explicit

Private Sub Populate()
Dim strsql As String

strsql = "select Name,Department,Sup_Nextel,Nextel,Cell,Supervisor,Supervisor_Cell from Sheet1 where Tech=" & cboTech.Text

' Get the recorset
Set rs = db.OpenRecordset(strsql)

' Put the info in the text fields
rs.MoveFirst ' Get first item
txtName.Text = rs!Name
txtDepartment.Text = rs!Department
txtSup_Nextel.Text = rs!Sup_Nextel
txtCell.Text = rs!Cell
txtNextel.Text = rs!Nextel
txtSupervisor.Text = rs!Supervisor
txtSUpervisor_cell.Text = rs!Supervisor_Cell


rs.Close
End Sub

Private Sub cboTech_click()
Populate
End Sub
Private Sub cboTech_()
Const MaxLength As Integer = 4 'the maximum
If Len(cboTech.Text) > MaxLength Then
cboTech.Text = Mid(cboTech.Text, 1, MaxLength)
End If
End Sub



Private Sub cmnd_close_Click()
Unload Me
End Sub

Private Sub cmndMin_Click()
WindowState = vbMinimized

End Sub

Private Sub Form_Load()
Me.Move (Screen.Width - Me.ScaleWidth) / 2, (Screen.Height - Me.ScaleHeight) / 2


Set db = DBEngine.OpenDatabase("\\timon\public\Aspect\Reports\Dispatch\2003\db\db1.mdb")
' Get the recorset
Set rs = db.OpenRecordset("select Tech from Sheet1")

' Grab all the items and put them in the combo box
rs.MoveFirst ' Get first item
While (Not rs.EOF)
If Not IsNull(rs!Tech) Then
cboTech.AddItem rs!Tech
End If
rs.MoveNext
Wend
rs.Close


cboTech.Text = cboTech.List(0)
Populate
End Sub


Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseX = X
MouseY = Y
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoEvents
If Button = vbLeftButton Then
Left = Left - (MouseX - X)
Top = Top - (MouseY - Y)
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
db.Close
End Sub

citizen_cow
04-16-2004, 08:41 AM
Ive created a second table labled "CSG" in the existing db.

What would I need to add a call much like the existing one to open the database and perform the same search functions.
I think if I just repeat the second half of this code and alter the table name it would cause an error. In fact im positive.

I assume I should just mimic the existing functions for moving through the database and all that when I write the functions for the third tab...


Private Sub Form_Load()
Me.Move (Screen.Width - Me.ScaleWidth) / 2, (Screen.Height - Me.ScaleHeight) / 2

' Open the database
Set db = DBEngine.OpenDatabase("\\timon\public\Aspect\Reports\Dispatch\2003\db\db1.mdb")
' Get the recorset
Set rs = db.OpenRecordset("select Tech from Sheet1")

' Grab all the items and put them in the combo box
rs.MoveFirst ' Get first item
While (Not rs.EOF) ' loop until no more items
If Not IsNull(rs!Tech) Then
cboTech.AddItem rs!Tech ' Put the Tech field in the box
End If
rs.MoveNext ' Get next item
Wend
rs.Close

' Set the first item of the list as the text of the combo box
cboTech.Text = cboTech.List(0)
Populate
End Sub

citizen_cow
04-18-2004, 06:18 AM
I hate to bump but Im not getting anywhere on my own. Im sure this is an easy fix but it still eludes me.

Ive searched this forum, searched other forums, searched the net in general and consulted my VB texts at home.

I just cant seem to figure out how to populate that last tab from a second table, how to open and connect to the table when I connect to my database without conflicting with the first table.

If anyone has a minute I would truely appreciate the time.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum