bradlannon
New member
- Local time
- , 23:00
- Joined
- May 26, 2009
- Messages
- 6
Hi,
I am wondering if someone wouldn't mind taking a look at this code. I'm new to Access and VB and I cannot seem to populate my txtboxes with my table data. It only seems to load 1 record, when I click next, nothing happens. Please note: lblmax.Caption = myRecordSet.MaxRecords pulls back 0. Please help!
I am wondering if someone wouldn't mind taking a look at this code. I'm new to Access and VB and I cannot seem to populate my txtboxes with my table data. It only seems to load 1 record, when I click next, nothing happens. Please note: lblmax.Caption = myRecordSet.MaxRecords pulls back 0. Please help!
Code:
Option Compare Database
Option Explicit
Public mySQL As String
Public myRecordSet As New ADODB.Recordset
Public cnn1 As ADODB.Connection
Public frm As Form
Public myName As String
Public myDesc As String
Private Sub cmdNextEmp_Click()
On Error GoTo Err_cmdNextEmp_Click
If myRecordSet.EOF Then
'do nothing
Else
myRecordSet.MoveNext
End If
Exit_cmdNextEmp_Click:
Exit Sub
Err_cmdNextEmp_Click:
MsgBox Err.Description
Resume Exit_cmdNextEmp_Click
End Sub
Private Sub cmdNextJob_Click()
If myRecordSet.EOF Then
'do nothing
Else
myRecordSet.MoveNext
End If
End Sub
Private Sub cmdPrevEmp_Click()
On Error GoTo Err_cmdPrevEmp_Click
If myRecordSet.BOF Then
'beginning
Else
DoCmd.GoToRecord , , acPrevious 'not beginning
End If
Exit_cmdPrevEmp_Click:
Exit Sub
Err_cmdPrevEmp_Click:
'MsgBox Err.Description
Resume Exit_cmdPrevEmp_Click
End Sub
Private Sub cmdReport_Click()
myDesc = lbldesc.Caption
myName = lblname.Caption
MsgBox myDesc
MsgBox myName
DoCmd.OpenReport "rptEmployeeBySpecificJob", acViewPreview, , "name=' & myName & ' AND Desc=' & myDesc &'"
End Sub
Private Sub cmdTest_Click()
End Sub
Private Sub Form_Load()
Set frm = Forms("frmEmployeeSpecificJob")
populateMyRecords
End Sub
Public Function populateMyRecords()
Dim strSelectedName As Integer
Set cnn1 = CurrentProject.Connection
myRecordSet.ActiveConnection = cnn1
'mySQL = "SELECT Jobs.Desc, Employees.name FROM Jobs, Employees"
mySQL = "SELECT Jobs.*, Employees.*, HoursEntry.jobID, HoursEntry.empID, HoursEntry.date, HoursEntry.hours, HoursEntry.travelHours FROM Jobs INNER JOIN (Employees INNER JOIN HoursEntry ON Employees.empID = HoursEntry.empID) ON Jobs.jobID = HoursEntry.jobID"
myRecordSet.Open mySQL
If myRecordSet.RecordCount > 0 Then
myRecordSet.MoveFirst
Do While Not myRecordSet.EOF
MsgBox myRecordSet![name]
MsgBox myRecordSet![Desc]
myRecordSet.MoveNext
Loop
Else
MsgBox ("must be no records i guess")
End If
lblname.Caption = myRecordSet![name]
lbldesc.Caption = myRecordSet![Desc]
lblmax.Caption = myRecordSet.MaxRecords
myRecordSet.MoveFirst
DoCmd.SetWarnings False
'Set myRecordSet = Nothing
End Function
Private Sub cmdPrevJobs_Click()
On Error GoTo Err_cmdPrevJobs_Click
If myRecordSet.BOF Then
'beginning
Else
DoCmd.GoToRecord , , acPrevious 'not beginning
End If
Exit_cmdPrevJobs_Click:
Exit Sub
Err_cmdPrevJobs_Click:
MsgBox Err.Description
Resume Exit_cmdPrevJobs_Click
End Sub