empty form to add table records problem

  • Thread starter Thread starter Jon_H
  • Start date Start date
J

Jon_H

I'm having a problem with a form which has 3 buttons submit, reset and
close.

the reset and close are ok.
how can I get the form to open up blank when launched and submit the data to
a table already created and clear the form when the submit button is
clicked.

I don't require the form to look at existing records.

regards
Jon_H
 
Assuming this form is bound to a table, you could put this code into the
Click event procedure of the button named cmdSubmit:
Private Sub cmdSubmit_Click()
If Me.Dirty Then
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub

Be sure to add error handling, in case there is a record why the record
cannot be saved (e.g. required field missing.)

Presumably the reset button should undo the entry that has not been saved
yet:
Private Sub cmdReset_Click()
If Me.Dirty Then
Me.Undo
End If
End Sub

If you expect your "Close" button to cancel any entry and close, undo the
form:
Private Sub cmdCancel_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

Alternatively, if you expect it to save and close:
Private Sub cmdClose_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub
 
In the property section of the form make sure the data entry is set to yes.
Then what is the code behind the submit button?

Try in the "on click event"

DoCmd.GoToRecord, , AcNewRec
 
Basically this is what I have . the reset button clears all fields except
the date. I would like the form to populate a table called faults with the
following fields
ID(AutoNumber),Date,Function,Caseref,Description,status

Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click

End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub

Private Sub cmdReset_Click()

Date = "Date"
pods = ""
Description = ""
Status = ""
Caseref = ""
pods.SetFocus

End Sub
 
Jon_H said:
Basically this is what I have . the reset button clears all fields except
the date. I would like the form to populate a table called faults with the
following fields
ID(AutoNumber),Date,Function,Caseref,Description,status

Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click

End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub

Private Sub cmdReset_Click()

Date = "Date"
pods = ""
Description = ""
Status = ""
Caseref = ""
pods.SetFocus

End Sub

I have also added the following which clears the form fields on a mouse up
event.

Private Sub cmdSubmit_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Date = ""
pods = ""
Description = ""
Status = ""
Caseref = ""
pods.SetFocus
End Sub

Cheers
Jon_H
 
Jon_H said:
I have also added the following which clears the form fields on a mouse up
event.

Private Sub cmdSubmit_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Date = ""
pods = ""
Description = ""
Status = ""
Caseref = ""
pods.SetFocus
End Sub

Cheers
Jon_H

I have managed to get it to work with the exception of filling in the date
field in the table.

any ideas

cheers
Jon_H
 
Back
Top