Storing a record before running qApp

Howlsta

Vampire Slayer
Local time
Today, 21:30
Joined
Jul 18, 2001
Messages
180
I've got a form where I can setup new students. Everytime a new student is created the operator has to press a cmdbutton which will append the student to their modules for that year. The problem is the button doesn't work, because the new student is not put in the tblStudent by Access until a navigation button is pressed or the form is closed. How do I get the code to add the student into the table, so that the append query will subsequently have records to add? I figured putting docmd.save before the openquery bit would do the trick but had no joy.
I've placed the current code below.
Any Ideas?

Private Sub cmdReg_Click()

On Error GoTo Err_cmdReg_Click

Dim stDocName As String
Dim rst As ADODB.Recordset

If IsNull(Me.cboYear) Or _
IsNull(Me.CboCourse) Then

MsgBox ("A Year and Course Must be Selected!"), (vbExclamation), _
("Empty Field(s)")
Exit Sub
Else
stDocName = "qAppRegisterStudent"
DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True

Exit_cmdReg_Click:
Exit Sub

Err_cmdReg_Click:
MsgBox Err.Description
Resume Exit_cmdReg_Click

End If

End Sub
 
Just a suggestion, but maybe on LostFocus of the last control you enter new data into? DoCmd.Save
SetFocus.CommandRunAppendQueryButton

Not sure what the form looks like.Is it built off of the query you are appending too?

Also, in your Code, I did not see where you added the DoCmd.Save. It does have to be done before the append query is run.
 
Instead of using:

DoCmd.Save

Try using:

DoCmd.RunCommand acCmdSaveRecord

Add this line before the execution of the Query in the code.

HTH
RDH
 
R Hicks: I'm curious. What is the difference in DoCmd.Save and DoCmd.RunCommand acCmdSaveRecord.

I'm not questioning your answer. Justwondering what your line of Code does? I've never seen it before. (Still new to VB)
 
That worked fine, thanks for the help everybody.

Rich
 

Users who are viewing this thread

Back
Top Bottom