Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Re-displaying a blank data entry form

Geek News

Re-displaying a blank data entry form
Mike 11/18/2008 5:22:04 PM
I have created a form that uses list boxes and text boxes to allow the user
to enter in data and then click a command button to add the record. I have
also created some VBA code to check and make sure that all the values are
valid before inserting the record into the table in the database. Once the
record is inserted, I would like to have the form re-display the same as if
it was opened for the first time. Currently, the data for the record just
entered stays in the fields.
Re: Re-displaying a blank data entry form
"Stuart McCall" <smccall[ at ]myunrealbox.com> 11/18/2008 5:36:06 PM
"Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
news:9EC5571E-36FD-43E9-8742-EA16DA298252[ at ]microsoft.com...
[Quoted Text]
>I have created a form that uses list boxes and text boxes to allow the user
> to enter in data and then click a command button to add the record. I
> have
> also created some VBA code to check and make sure that all the values are
> valid before inserting the record into the table in the database. Once
> the
> record is inserted, I would like to have the form re-display the same as
> if
> it was opened for the first time. Currently, the data for the record
> just
> entered stays in the fields.

There's more than one way to achieve this, but I think the method you want
is to set the form's DataEntry property to Yes/True. Give it a try and see
what happens.


Re: Re-displaying a blank data entry form
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 11/18/2008 5:39:57 PM
"Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
news:9EC5571E-36FD-43E9-8742-EA16DA298252[ at ]microsoft.com...
[Quoted Text]
>I have created a form that uses list boxes and text boxes to allow the user
> to enter in data and then click a command button to add the record. I
> have
> also created some VBA code to check and make sure that all the values are
> valid before inserting the record into the table in the database. Once
> the
> record is inserted, I would like to have the form re-display the same as
> if
> it was opened for the first time. Currently, the data for the record
> just
> entered stays in the fields.


Is this a bound form, or an unbound form? If it's a bound form, add a line
of code to tell the form to go to a new record:

RunCommand acCmdRecordsGoToNew

If it's an unbound form, you'll have to go through the form's controls and
set each editable control to Null (or to a default value, if the control has
one).

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Re: Re-displaying a blank data entry form
Mike 11/18/2008 6:36:01 PM
Dirk,
I am fairly new to this but I think it is an unbound form. Once the
user clicks the button, it updates only one table, but the form itself has 3
list boxes that are used to get information from other table. I tried
setting the controls for each field on the form and changed it to null, but
still the data stayed on the form after adding the record to the table. I
have also changed the form's properties as Stuart had suggested.

"Dirk Goldgar" wrote:

[Quoted Text]
> "Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
> news:9EC5571E-36FD-43E9-8742-EA16DA298252[ at ]microsoft.com...
> >I have created a form that uses list boxes and text boxes to allow the user
> > to enter in data and then click a command button to add the record. I
> > have
> > also created some VBA code to check and make sure that all the values are
> > valid before inserting the record into the table in the database. Once
> > the
> > record is inserted, I would like to have the form re-display the same as
> > if
> > it was opened for the first time. Currently, the data for the record
> > just
> > entered stays in the fields.
>
>
> Is this a bound form, or an unbound form? If it's a bound form, add a line
> of code to tell the form to go to a new record:
>
> RunCommand acCmdRecordsGoToNew
>
> If it's an unbound form, you'll have to go through the form's controls and
> set each editable control to Null (or to a default value, if the control has
> one).
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
Re: Re-displaying a blank data entry form
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 11/18/2008 6:47:10 PM
"Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
news:986ECB30-7CDE-4E38-91D9-6E78FA53CAA3[ at ]microsoft.com...
[Quoted Text]
> Dirk,
> I am fairly new to this but I think it is an unbound form. Once the
> user clicks the button, it updates only one table, but the form itself has
> 3
> list boxes that are used to get information from other table. I tried
> setting the controls for each field on the form and changed it to null,
> but
> still the data stayed on the form after adding the record to the table. I
> have also changed the form's properties as Stuart had suggested.


Stuart's suggestion was a good one, but much depends on how you have the
form set up. Please post the form's Record Source property -- if that
property is blank, it's an unbound form -- and also the code or macro that
is executed by the button.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Re: Re-displaying a blank data entry form
Mike 11/18/2008 7:07:03 PM
The record source is blank so it is unbound. Here is the code that I have
when the user clicks the add record button:

Private Sub Add_Record_Click()

' RS is for the audit name table
' RS1 is for the HR Dept Name Table
' RS2 is for the HR SR Mgr Name Table
Dim rs As DAO.Recordset, rs1 As DAO.Recordset, rs2 As DAO.Recordset
Dim db As DAO.Database
Dim strSQL As String
Dim tmpAuditEntityNum As Integer, tmpHRDeptNum As Integer, tmpHR_SRmgrNum As
Integer
Dim tmpAuditEntityName As String, tmpHRDeptName As String, tmpHR_SRmgrName
As String
Dim Response As Integer, Response1 As Integer, FormBlank As String


Response = MsgBox("This action will insert the Audit Record into the
main Audit table." & _
vbCrLf & vbCrLf & "Are you sure?", vbYesNo, "Confirmation...")

If Response = vbNo Then Exit Sub

' Check to ensure data entered in key fields before adding records.

FormBlank = "False"
FormBlank = IsNull(Me.frmAudit_Name)
FormBlank = IsNull(Me.frmAudit_Entity_Name)
FormBlank = IsNull(Me.frmAudit_Start_Date)
FormBlank = IsNull(Me.frmTarget_Close_Date)
FormBlank = IsNull(Me.frmHR_Dept_Name)
FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)

If FormBlank = "True" Then
MsgBox ("Empty fields not allowed to add form." & _
"Fix errors and try again")
Exit Sub
End If


' Form input fields from table use the first column when accessing the field.
' That is why name is moved to number.

tmpAuditEntityNum = Me.frmAudit_Entity_Name
tmpHRDeptNum = Me.frmHR_Dept_Name
tmpHR_SRmgrNum = Me.frmHR_SR_Mgr_Name

Set db = CurrentDb

DoCmd.Hourglass True
DoCmd.SetWarnings False


strSQL = ("Select Audit_Entity_Name ")
strSQL = strSQL & ("From tblAudit_Entity")
strSQL = strSQL & (" Where (tblAudit_Entity.Audit_Entity_Num = " &
tmpAuditEntityNum & ")")
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then
MsgBox ("Audit Entity not valid in table. Contact the application
administrator")
Exit Sub
Else
tmpAuditEntityName = rs!Audit_Entity_Name
End If

strSQL = ("Select HR_Dept_Name ")
strSQL = strSQL & ("From tblHR_Dept")
strSQL = strSQL & (" Where (tblHR_Dept.HR_Dept_Num = " & tmpHRDeptNum &
")")
Set rs1 = db.OpenRecordset(strSQL)
If rs1.RecordCount = 0 Then
MsgBox ("HR Department not valid in table. Contact the application
administrator")
Exit Sub
Else
tmpHRDeptName = rs1!HR_Dept_Name
End If

strSQL = ("Select HR_SR_Mgr_Name ")
strSQL = strSQL & ("From tbl_HR_SR_Manager")
strSQL = strSQL & (" Where (tbl_HR_SR_Manager.HR_SR_Mgr_Num = " &
tmpHR_SRmgrNum & ")")
Set rs2 = db.OpenRecordset(strSQL)
If rs2.RecordCount = 0 Then
MsgBox ("HR SR Manager not valid in table. Contact the application
administrator")
Exit Sub
Else
tmpHR_SRmgrName = rs2!HR_SR_Mgr_Name
End If

Response1 = MsgBox("Audit Entity Number is " & tmpAuditEntityNum & "." & _
vbCrLf & vbCrLf & "HR Dept Number is " & tmpHRDeptNum & "." & _
vbCrLf & vbCrLf & "HR SR Mgr Number is " & tmpHR_SRmgrNum &
"." & _
vbCrLf & vbCrLf & "You Sure", vbYesNo, "Confirmation...")

Call Add_Audit_Rcd(Me.frmAudit_Name, tmpAuditEntityNum,
Me.frmAudit_Start_Date, _
Me.frmTarget_Close_Date, tmpHRDeptNum, tmpHR_SRmgrNum, Me.frmSOX,
Me.frmOperational)

DoCmd.SetWarnings True
DoCmd.Hourglass False

MsgBox "Record Added", , "Done"



End Sub

"Dirk Goldgar" wrote:

[Quoted Text]
> "Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
> news:986ECB30-7CDE-4E38-91D9-6E78FA53CAA3[ at ]microsoft.com...
> > Dirk,
> > I am fairly new to this but I think it is an unbound form. Once the
> > user clicks the button, it updates only one table, but the form itself has
> > 3
> > list boxes that are used to get information from other table. I tried
> > setting the controls for each field on the form and changed it to null,
> > but
> > still the data stayed on the form after adding the record to the table. I
> > have also changed the form's properties as Stuart had suggested.
>
>
> Stuart's suggestion was a good one, but much depends on how you have the
> form set up. Please post the form's Record Source property -- if that
> property is blank, it's an unbound form -- and also the code or macro that
> is executed by the button.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
Re: Re-displaying a blank data entry form
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 11/18/2008 7:58:14 PM
"Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
news:1951729F-B3C7-4E45-8359-303D0FD1513C[ at ]microsoft.com...
[Quoted Text]
> The record source is blank so it is unbound. Here is the code that I have
> when the user clicks the add record button:
>
> Private Sub Add_Record_Click()
>
> ' RS is for the audit name table
> ' RS1 is for the HR Dept Name Table
> ' RS2 is for the HR SR Mgr Name Table
> Dim rs As DAO.Recordset, rs1 As DAO.Recordset, rs2 As DAO.Recordset
> Dim db As DAO.Database
> Dim strSQL As String
> Dim tmpAuditEntityNum As Integer, tmpHRDeptNum As Integer, tmpHR_SRmgrNum
> As
> Integer
> Dim tmpAuditEntityName As String, tmpHRDeptName As String, tmpHR_SRmgrName
> As String
> Dim Response As Integer, Response1 As Integer, FormBlank As String
>
>
> Response = MsgBox("This action will insert the Audit Record into the
> main Audit table." & _
> vbCrLf & vbCrLf & "Are you sure?", vbYesNo,
> "Confirmation...")
>
> If Response = vbNo Then Exit Sub
>
> ' Check to ensure data entered in key fields before adding records.
>
> FormBlank = "False"
> FormBlank = IsNull(Me.frmAudit_Name)
> FormBlank = IsNull(Me.frmAudit_Entity_Name)
> FormBlank = IsNull(Me.frmAudit_Start_Date)
> FormBlank = IsNull(Me.frmTarget_Close_Date)
> FormBlank = IsNull(Me.frmHR_Dept_Name)
> FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)
>
> If FormBlank = "True" Then
> MsgBox ("Empty fields not allowed to add form." & _
> "Fix errors and try again")
> Exit Sub
> End If
>
>
> ' Form input fields from table use the first column when accessing the
> field.
> ' That is why name is moved to number.
>
> tmpAuditEntityNum = Me.frmAudit_Entity_Name
> tmpHRDeptNum = Me.frmHR_Dept_Name
> tmpHR_SRmgrNum = Me.frmHR_SR_Mgr_Name
>
> Set db = CurrentDb
>
> DoCmd.Hourglass True
> DoCmd.SetWarnings False
>
>
> strSQL = ("Select Audit_Entity_Name ")
> strSQL = strSQL & ("From tblAudit_Entity")
> strSQL = strSQL & (" Where (tblAudit_Entity.Audit_Entity_Num = " &
> tmpAuditEntityNum & ")")
> Set rs = db.OpenRecordset(strSQL)
> If rs.RecordCount = 0 Then
> MsgBox ("Audit Entity not valid in table. Contact the application
> administrator")
> Exit Sub
> Else
> tmpAuditEntityName = rs!Audit_Entity_Name
> End If
>
> strSQL = ("Select HR_Dept_Name ")
> strSQL = strSQL & ("From tblHR_Dept")
> strSQL = strSQL & (" Where (tblHR_Dept.HR_Dept_Num = " & tmpHRDeptNum &
> ")")
> Set rs1 = db.OpenRecordset(strSQL)
> If rs1.RecordCount = 0 Then
> MsgBox ("HR Department not valid in table. Contact the
> application
> administrator")
> Exit Sub
> Else
> tmpHRDeptName = rs1!HR_Dept_Name
> End If
>
> strSQL = ("Select HR_SR_Mgr_Name ")
> strSQL = strSQL & ("From tbl_HR_SR_Manager")
> strSQL = strSQL & (" Where (tbl_HR_SR_Manager.HR_SR_Mgr_Num = " &
> tmpHR_SRmgrNum & ")")
> Set rs2 = db.OpenRecordset(strSQL)
> If rs2.RecordCount = 0 Then
> MsgBox ("HR SR Manager not valid in table. Contact the
> application
> administrator")
> Exit Sub
> Else
> tmpHR_SRmgrName = rs2!HR_SR_Mgr_Name
> End If
>
> Response1 = MsgBox("Audit Entity Number is " & tmpAuditEntityNum & "."
> & _
> vbCrLf & vbCrLf & "HR Dept Number is " & tmpHRDeptNum & "."
> & _
> vbCrLf & vbCrLf & "HR SR Mgr Number is " & tmpHR_SRmgrNum &
> "." & _
> vbCrLf & vbCrLf & "You Sure", vbYesNo, "Confirmation...")
>
> Call Add_Audit_Rcd(Me.frmAudit_Name, tmpAuditEntityNum,
> Me.frmAudit_Start_Date, _
> Me.frmTarget_Close_Date, tmpHRDeptNum, tmpHR_SRmgrNum, Me.frmSOX,
> Me.frmOperational)
>
> DoCmd.SetWarnings True
> DoCmd.Hourglass False
>
> MsgBox "Record Added", , "Done"
>
>
>
> End Sub


Okay, I see that it is unbound, and that you call another routine,
Add_Audit_Rcd, to add the record. After that, I gather you want to clear
the form. To do that, I would expect that code along these lines would do
the job:

Me.frmAudit_Name = Null
Me.frmAudit_Entity_Name = Null
Me.frmAudit_Start_Date = Null
Me.frmTarget_Close_Date = Null
Me.frmHR_Dept_Name = Null
Me.frmHR_SR_Mgr_Name = Null
Me.frmSOX = Null
Me.frmOperational = Null

It's possible I've "nulled" some fields there that should not be nulled, and
I may have left out some fields that should have been included. You'll have
to check that.

If any of those fields should be reset to a default value instead of Null,
you can set them with reference to their DefaultValue properties like this:

Me.<controlname> = Eval(Me.<controlname>.DefaultValue)

Please let me know if this approach works for you.

Aside from that, I'm concerned about somethings I see that may be errors in
your code. For example, the code that checks for blank fields:

> Dim Response As Integer, Response1 As Integer, FormBlank As String
[...]
> ' Check to ensure data entered in key fields before adding records.
>
> FormBlank = "False"
> FormBlank = IsNull(Me.frmAudit_Name)
> FormBlank = IsNull(Me.frmAudit_Entity_Name)
> FormBlank = IsNull(Me.frmAudit_Start_Date)
> FormBlank = IsNull(Me.frmTarget_Close_Date)
> FormBlank = IsNull(Me.frmHR_Dept_Name)
> FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)
>
> If FormBlank = "True" Then

First, FormBlank should be declared and tested as Boolean, not String:

Dim FormBlank As Boolean

FormBlank = False
[...]
If FormBlank = True Then

But on top of that, the code you posted will result in FormBlank set to True
(or "True") only if Me.frmHR_SR_Mgr_Name is Null. That's because this is
the last statement executed in the series of tests:

> FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)

So the result of that IsNull() expression is assigned to FormBlank, and
that's the end of it.

Instead, you want to do something like this:

FormBlank = _
IsNull(Me.frmAudit_Name) _
Or IsNull(Me.frmAudit_Entity_Name) _
Or IsNull(Me.frmAudit_Start_Date) _
Or IsNull(Me.frmTarget_Close_Date) _
Or IsNull(Me.frmHR_Dept_Name) _
Or IsNull(Me.frmHR_SR_Mgr_Name)

There are other, possibly more efficient, ways to accomplish this, but that
should be pretty clear.

I'm also concerned about your use of "DoCmd.SetWarnings False". I see no
reason within this procedure for doing that, and the scope of SetWarnings
False should be as minimal as possible. You may have a reason to use it
inside the Add_Audit_Rcd procedure, in which case you should limit it to
that procedure. And any procedure where you turn off warnings should also
have error-handling in place so that there is no way to exit the procedure,
even in the event of an error, with warnings turned off.

In this procedure you have posted, there are lots of ways to leave the
procedure with both warnings turned off and Hourglass turned on. You should
correct that, so that (a) warnings are never turned off in this procedure at
all, and (b) there is no way to exit the procedure without turning off the
Hourglass.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Re: Re-displaying a blank data entry form
Mike 11/18/2008 8:25:02 PM
Dirk,
Your suggestion of setting the fields individually to null worked
perfectly. I also made the other code changes you suggested. THanks a
lot. As a newbie to doing some of this I am just copying what others had
done before me and fixing as I learn more.

"Dirk Goldgar" wrote:

[Quoted Text]
> "Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
> news:1951729F-B3C7-4E45-8359-303D0FD1513C[ at ]microsoft.com...
> > The record source is blank so it is unbound. Here is the code that I have
> > when the user clicks the add record button:
> >
> > Private Sub Add_Record_Click()
> >
> > ' RS is for the audit name table
> > ' RS1 is for the HR Dept Name Table
> > ' RS2 is for the HR SR Mgr Name Table
> > Dim rs As DAO.Recordset, rs1 As DAO.Recordset, rs2 As DAO.Recordset
> > Dim db As DAO.Database
> > Dim strSQL As String
> > Dim tmpAuditEntityNum As Integer, tmpHRDeptNum As Integer, tmpHR_SRmgrNum
> > As
> > Integer
> > Dim tmpAuditEntityName As String, tmpHRDeptName As String, tmpHR_SRmgrName
> > As String
> > Dim Response As Integer, Response1 As Integer, FormBlank As String
> >
> >
> > Response = MsgBox("This action will insert the Audit Record into the
> > main Audit table." & _
> > vbCrLf & vbCrLf & "Are you sure?", vbYesNo,
> > "Confirmation...")
> >
> > If Response = vbNo Then Exit Sub
> >
> > ' Check to ensure data entered in key fields before adding records.
> >
> > FormBlank = "False"
> > FormBlank = IsNull(Me.frmAudit_Name)
> > FormBlank = IsNull(Me.frmAudit_Entity_Name)
> > FormBlank = IsNull(Me.frmAudit_Start_Date)
> > FormBlank = IsNull(Me.frmTarget_Close_Date)
> > FormBlank = IsNull(Me.frmHR_Dept_Name)
> > FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)
> >
> > If FormBlank = "True" Then
> > MsgBox ("Empty fields not allowed to add form." & _
> > "Fix errors and try again")
> > Exit Sub
> > End If
> >
> >
> > ' Form input fields from table use the first column when accessing the
> > field.
> > ' That is why name is moved to number.
> >
> > tmpAuditEntityNum = Me.frmAudit_Entity_Name
> > tmpHRDeptNum = Me.frmHR_Dept_Name
> > tmpHR_SRmgrNum = Me.frmHR_SR_Mgr_Name
> >
> > Set db = CurrentDb
> >
> > DoCmd.Hourglass True
> > DoCmd.SetWarnings False
> >
> >
> > strSQL = ("Select Audit_Entity_Name ")
> > strSQL = strSQL & ("From tblAudit_Entity")
> > strSQL = strSQL & (" Where (tblAudit_Entity.Audit_Entity_Num = " &
> > tmpAuditEntityNum & ")")
> > Set rs = db.OpenRecordset(strSQL)
> > If rs.RecordCount = 0 Then
> > MsgBox ("Audit Entity not valid in table. Contact the application
> > administrator")
> > Exit Sub
> > Else
> > tmpAuditEntityName = rs!Audit_Entity_Name
> > End If
> >
> > strSQL = ("Select HR_Dept_Name ")
> > strSQL = strSQL & ("From tblHR_Dept")
> > strSQL = strSQL & (" Where (tblHR_Dept.HR_Dept_Num = " & tmpHRDeptNum &
> > ")")
> > Set rs1 = db.OpenRecordset(strSQL)
> > If rs1.RecordCount = 0 Then
> > MsgBox ("HR Department not valid in table. Contact the
> > application
> > administrator")
> > Exit Sub
> > Else
> > tmpHRDeptName = rs1!HR_Dept_Name
> > End If
> >
> > strSQL = ("Select HR_SR_Mgr_Name ")
> > strSQL = strSQL & ("From tbl_HR_SR_Manager")
> > strSQL = strSQL & (" Where (tbl_HR_SR_Manager.HR_SR_Mgr_Num = " &
> > tmpHR_SRmgrNum & ")")
> > Set rs2 = db.OpenRecordset(strSQL)
> > If rs2.RecordCount = 0 Then
> > MsgBox ("HR SR Manager not valid in table. Contact the
> > application
> > administrator")
> > Exit Sub
> > Else
> > tmpHR_SRmgrName = rs2!HR_SR_Mgr_Name
> > End If
> >
> > Response1 = MsgBox("Audit Entity Number is " & tmpAuditEntityNum & "."
> > & _
> > vbCrLf & vbCrLf & "HR Dept Number is " & tmpHRDeptNum & "."
> > & _
> > vbCrLf & vbCrLf & "HR SR Mgr Number is " & tmpHR_SRmgrNum &
> > "." & _
> > vbCrLf & vbCrLf & "You Sure", vbYesNo, "Confirmation...")
> >
> > Call Add_Audit_Rcd(Me.frmAudit_Name, tmpAuditEntityNum,
> > Me.frmAudit_Start_Date, _
> > Me.frmTarget_Close_Date, tmpHRDeptNum, tmpHR_SRmgrNum, Me.frmSOX,
> > Me.frmOperational)
> >
> > DoCmd.SetWarnings True
> > DoCmd.Hourglass False
> >
> > MsgBox "Record Added", , "Done"
> >
> >
> >
> > End Sub
>
>
> Okay, I see that it is unbound, and that you call another routine,
> Add_Audit_Rcd, to add the record. After that, I gather you want to clear
> the form. To do that, I would expect that code along these lines would do
> the job:
>
> Me.frmAudit_Name = Null
> Me.frmAudit_Entity_Name = Null
> Me.frmAudit_Start_Date = Null
> Me.frmTarget_Close_Date = Null
> Me.frmHR_Dept_Name = Null
> Me.frmHR_SR_Mgr_Name = Null
> Me.frmSOX = Null
> Me.frmOperational = Null
>
> It's possible I've "nulled" some fields there that should not be nulled, and
> I may have left out some fields that should have been included. You'll have
> to check that.
>
> If any of those fields should be reset to a default value instead of Null,
> you can set them with reference to their DefaultValue properties like this:
>
> Me.<controlname> = Eval(Me.<controlname>.DefaultValue)
>
> Please let me know if this approach works for you.
>
> Aside from that, I'm concerned about somethings I see that may be errors in
> your code. For example, the code that checks for blank fields:
>
> > Dim Response As Integer, Response1 As Integer, FormBlank As String
> [...]
> > ' Check to ensure data entered in key fields before adding records.
> >
> > FormBlank = "False"
> > FormBlank = IsNull(Me.frmAudit_Name)
> > FormBlank = IsNull(Me.frmAudit_Entity_Name)
> > FormBlank = IsNull(Me.frmAudit_Start_Date)
> > FormBlank = IsNull(Me.frmTarget_Close_Date)
> > FormBlank = IsNull(Me.frmHR_Dept_Name)
> > FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)
> >
> > If FormBlank = "True" Then
>
> First, FormBlank should be declared and tested as Boolean, not String:
>
> Dim FormBlank As Boolean
>
> FormBlank = False
> [...]
> If FormBlank = True Then
>
> But on top of that, the code you posted will result in FormBlank set to True
> (or "True") only if Me.frmHR_SR_Mgr_Name is Null. That's because this is
> the last statement executed in the series of tests:
>
> > FormBlank = IsNull(Me.frmHR_SR_Mgr_Name)
>
> So the result of that IsNull() expression is assigned to FormBlank, and
> that's the end of it.
>
> Instead, you want to do something like this:
>
> FormBlank = _
> IsNull(Me.frmAudit_Name) _
> Or IsNull(Me.frmAudit_Entity_Name) _
> Or IsNull(Me.frmAudit_Start_Date) _
> Or IsNull(Me.frmTarget_Close_Date) _
> Or IsNull(Me.frmHR_Dept_Name) _
> Or IsNull(Me.frmHR_SR_Mgr_Name)
>
> There are other, possibly more efficient, ways to accomplish this, but that
> should be pretty clear.
>
> I'm also concerned about your use of "DoCmd.SetWarnings False". I see no
> reason within this procedure for doing that, and the scope of SetWarnings
> False should be as minimal as possible. You may have a reason to use it
> inside the Add_Audit_Rcd procedure, in which case you should limit it to
> that procedure. And any procedure where you turn off warnings should also
> have error-handling in place so that there is no way to exit the procedure,
> even in the event of an error, with warnings turned off.
>
> In this procedure you have posted, there are lots of ways to leave the
> procedure with both warnings turned off and Hourglass turned on. You should
> correct that, so that (a) warnings are never turned off in this procedure at
> all, and (b) there is no way to exit the procedure without turning off the
> Hourglass.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
Re: Re-displaying a blank data entry form
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 11/18/2008 8:31:39 PM
"Mike" <Mike[ at ]discussions.microsoft.com> wrote in message
news:0B0929A0-BD7A-4BD8-9599-79E406DA1658[ at ]microsoft.com...
[Quoted Text]
> Dirk,
> Your suggestion of setting the fields individually to null worked
> perfectly. I also made the other code changes you suggested. THanks a
> lot. As a newbie to doing some of this I am just copying what others had
> done before me and fixing as I learn more.


Very good.

I just noticed something else: you should close your various recordsets
when you're done with them. That may involve rearranging your code slightly
(if you haven't already done so) so that you don't exit the procedure before
you close the recordsets.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net