Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help appending table

Status
Not open for further replies.

autoIT

IS-IT--Management
May 10, 2006
68
US
OK i've been pulling my hair out here and my eyes are bugging out. I need another set of eyes to look this over. I am including code that will allow the EU to enter info for a new record and this info will be appended to a table int he same database. I will include the code from form load to give you an idea of the connection and recoedset as well as the code for the insert button. I have a feeling a line of code is in the wrong spot. Oh yeah, the table gets updated, but with a blank line. The info is pulled from the table tot he form just fine.


Private Sub btnPrev_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
End If

FillControls

End Sub

Private Sub Form_Load()
On Error GoTo Error_Handler
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.BackColor = vbWhite
ctl.SetFocus
ctl.Text = ""
txtEmpName.SetFocus
End If
Next

Set cn = CurrentProject.Connection
rs.ActiveConnection = cn

rs.Open "employees", cn, adOpenDynamic, adLockOptimistic, adCmdTable

FillControls


btnNext.Visible = True
btnPrev.Visible = True
btnNew.Visible = True
btnDelete.Visible = True
btnInsert.Visible = False

Exit Sub

Error_Handler:

MsgBox Err.Description & vbCrLf & "Error NUmber:" & Err.Number


Private Sub btnPrev_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
End If

FillControls

End Sub

Private Sub Form_Load()
On Error GoTo Error_Handler
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.BackColor = vbWhite
ctl.SetFocus
ctl.Text = ""
txtEmpName.SetFocus
End If
Next

Set cn = CurrentProject.Connection
rs.ActiveConnection = cn

rs.Open "employees", cn, adOpenDynamic, adLockOptimistic, adCmdTable

FillControls


btnNext.Visible = True
btnPrev.Visible = True
btnNew.Visible = True
btnDelete.Visible = True
btnInsert.Visible = False

Exit Sub

Error_Handler:

MsgBox Err.Description & vbCrLf & "Error NUmber:" & Err.Number


****here is the fillcontrol sub***
Private Sub FillControls()
txtEmpName.SetFocus
txtEmpName.Text = rs.Fields.Item("Employee Name")
txtDept.SetFocus
txtDept.Text = rs.Fields.Item("Department")
txtPP.SetFocus
txtPP.Text = rs.Fields.Item("Pay Period")
txtSchedHrs.SetFocus
txtSchedHrs.Text = rs.Fields.Item("Hours Scheduled")
txtA.SetFocus
txtA.Text = rs.Fields.Item("A Time")
txtB.SetFocus
txtB.Text = rs.Fields.Item("B Time")


End Sub
 
Try changing
Private Sub FillControls()

To

Private Sub FillControls(ByVal RS as recordset)

and change all "fillcontrols" in the rest of the module to

fillcontrols RS
 
sorry, I was on the trigger. Anyhow code didnt work gave me another error should code look like:

txtEmpName.text=FillControlsrs.Fields.Item...

or

txtEmpName.text=FillControls.rs.Fields.Item...


Also, does it matter where I use rs.addnew and rs.update in the module for the INsert Button?


Adam
 
Woops...

I didn't mean

Code:
Private Sub FillControls(ByVal RS as recordset)

I meant

Code:
Private Sub FillControls(ByRef RS as recordset)

Also, does it matter where I use rs.addnew and rs.update in the module for the INsert Button?

Not sure what you mean. Where in the module doesn't matter... the sequence of procedures doesn't matter. I am assuming you are going to put it on the click event of a button?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top