Log in

View Full Version : Opening Form result in a blank record in DB



bigal.nz
07-09-2016, 08:23 PM
Hi All,

I have got this horrible issue where when I open my form based on a record set, the first record is always a blank and it ends up entering a blank record into my database, even though the record set itself contains no blanks.

Here is the code:



'------------------------------------------------------------
' CmdInput_Click
' Retrieve All Records where Status is not set AND show on input form
' Show daily meeting
'------------------------------------------------------------
Private Sub CmdSAMInput_Click()

Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT * FROM SAM WHERE SAMStatus IS NULL;"
Set rs = CurrentDb.OpenRecordset(strSQL)

If rs.RecordCount > 0 Then
DoCmd.OpenForm "SAM Input", acNormal
Forms![SAM Input].RecordSource = strSQL
Forms![SAM Input].Requery
Else
MsgBox ("There are no new Recordset to show")
End If

End Sub

How do I stop this behaviour?

Not that I do want to allow editing on this form, I just don't want it to keep showing a first blank record which ends up going into my database.

Cheers

-Al

jonh
07-11-2016, 09:07 AM
I don't know what the particular issue is but if you really must set the sql of the recordest I would suggest putting it in the forms onopen event so it isn't doing two loads.