PDA

View Full Version : Urgent request - AddRecord issue (VBA)



technocraze
01-11-2007, 08:02 AM
Hi guys,

i tried using the AddRecord command (Record operation - Add New Record) provided by MS Acess but the new record is not been appended to the table but instead it has been overwritten. I have set the focus for the field under the acNewRec already. By right i shld be able to append the record at the end of the record of the field and nt overwritting the record. What i want to achieve is to be able to select the value from the combo box corresponding to the table 'Student' and append the record based on what have been selected from the combo box (Predefined list) and the remaining textbox values.

Implementation logic

primary key
SerialCode (Autokey)

Fields
StudentId, subjectcode, course, grade

Combo box
StudentId (predefined list) - S1, S2, S3, S4, S4, S5

AddRecord command (by Acess under operation)
acNewRc
StudentId.SetFocus
subjectCode.SetFocus
course.SetFocus
grade.SetFocus

code

Private Sub AddRecord_Click()
On Error GoTo AddRecord_Click
DoCmd.OpenForm "Record"
DoCmd.GoToRecord, "Record", acNewRec
Combo1.SetFocus 'predefined list
StudentId.SetFocus 'bound to controlsource studentId
course.SetFocus 'bound to controlsource course
subjectCode.SetFocus
Grade.SetFocus
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub
Private Sub Combo1_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[SerialCode] = " & Str(Nz(Me![Combo1], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


Tks for your assistance.

OBP
01-11-2007, 09:52 AM
Why are you using VBA to do it this way, why not just add the record in a form as normal?
Do you want to make selections in a form and use those selections to create or add a record in another table?