Refresh Form Prior to Append Query

I

Ian

I think this is a simple question but.....
I have a form with an 'accept' button I've built at the bottom. When the
user hits accept is runs an append query using some of the data in the form
in the query then closes the form. The first time I hit the accept button
none of the data is grabbed by the query but if I open the form a second
time, hit the accept button a second time it works. I think I need to
refresh the form prior to running the query. Here's part of the code for the
accept button;

On Error GoTo Err_Accept_Click
'prevent entering drug without user or expire date
If IsNull(Me!TotQuan) Or IsNull(Me!ReceivedBy) Or IsNull(Me!ExpireDate)
Then
MsgBox "'Expire Date'; Quantity' or 'Received By' is blank", vbCritical
Else
DoCmd.OpenQuery "Qry_DistCreateEntry"
DoCmd.Close
End If

Qry_DistCreateEntry is the append query and grabs data such as
[forms].[frm_drugentry].[id] for the append.

Do I need another statement below the Else command? Thx. Ian.
 
P

pietlinden

I think this is a simple question but.....
I have a form with an 'accept' button I've built at the bottom.  When the
user hits accept is runs an append query using some of the data in the form
in the query then closes the form.  The first time I hit the accept button
none of the data is grabbed by the query but if I open the form a second
time, hit the accept button a second time it works.   I think I need to
refresh the form prior to running the query.  Here's part of the code for the
accept button;

On Error GoTo Err_Accept_Click
'prevent entering drug without user or expire date
    If IsNull(Me!TotQuan) Or IsNull(Me!ReceivedBy) Or IsNull(Me!ExpireDate)
Then
    MsgBox "'Expire Date'; Quantity' or 'Received By' is blank", vbCritical
    Else
    DoCmd.OpenQuery "Qry_DistCreateEntry"
    DoCmd.Close
    End If

Qry_DistCreateEntry is the append query and grabs data such as
[forms].[frm_drugentry].[id] for the append.

Do I need another statement below the Else command?  Thx. Ian.

use the Requery method of the form to refresh all the data.
 
I

Ian

worked perfectly - thx. On another note, is there a way to open the form to
a fresh form? I've set it to additions only but it brings up the last
record.

I think this is a simple question but.....
I have a form with an 'accept' button I've built at the bottom. When the
user hits accept is runs an append query using some of the data in the form
in the query then closes the form. The first time I hit the accept button
none of the data is grabbed by the query but if I open the form a second
time, hit the accept button a second time it works. I think I need to
refresh the form prior to running the query. Here's part of the code for the
accept button;

On Error GoTo Err_Accept_Click
'prevent entering drug without user or expire date
If IsNull(Me!TotQuan) Or IsNull(Me!ReceivedBy) Or IsNull(Me!ExpireDate)
Then
MsgBox "'Expire Date'; Quantity' or 'Received By' is blank", vbCritical
Else
DoCmd.OpenQuery "Qry_DistCreateEntry"
DoCmd.Close
End If

Qry_DistCreateEntry is the append query and grabs data such as
[forms].[frm_drugentry].[id] for the append.

Do I need another statement below the Else command? Thx. Ian.

use the Requery method of the form to refresh all the data.
 
P

pietlinden

worked perfectly - thx.  On another note, is there a way to open the form to
a fresh form?  I've set it to additions only but it brings up the last
record.  

DoCmd.OpenForm "TimeCard", acNormal, , , acFormAdd, acWindowNormal
 
J

John Spencer

It sounds as if the data has not been saved. I would add this line
right before trying to run the query. It will save any unsaved changes.

If Me.Dirty = True Then Me.Dirty = False

DoCmd.OpenQuery "Qry_DistCreateEntry"

DoCmd.Close acForm, Me.Name '<<< close this form



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top