Solved

code for new record and refresh query and form in MS Access

Posted on 2007-03-30
15
281 Views
Last Modified: 2008-02-01
What code do I use to being a new record and refresh the query (and thus the form where the command button resides)?

I tried

DoCmd.GoToRecord , , acNewRec
Me.Refresh

and no luck

Thanks.
0
Comment
Question by:mamadouthiam
  • 9
  • 6
15 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18825392
Hi mamadouthiam,
from your description, I can't tell what it is you are trying to accomplish and what is not working in relation to what you are looking for.  Thanks.

PDB  
0
 

Author Comment

by:mamadouthiam
ID: 18825422
Sorry,

I have a form for data entry where the user will click a command to start a new record.  The form is based on query and the field that I want o populate when they click (and start a new record) is a combination of an Autonum field and a text string.

Thus, when they click "start new request", the "tracking field should populate with "OurCompany - 1". If they click again, it shoudl start a new record that says "OurCompany - 2".

Does this help?
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18825509
Try this:
DoCmd.GoToRecord , , acNewRec
Me.Dirty = False

or this:
DoCmd.GoToRecord , , acNewRec
Me!TrackingField.Recalc
Me.Dirty = False
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:mamadouthiam
ID: 18825640
puppydogbuddy,

No good.

DoCmd.GoToRecord , , acNewRec ---> Nothing
Me.Dirty = False

or this:

DoCmd.GoToRecord , , acNewRec --> Error, object doesn't support...
Me!TrackingField.Recalc
Me.Dirty = False

I think I know what should happen.  

New Record
Requery (qrymyqery)
Refresh

I just don't know the syntax
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18825762
Did you open form before issuing goto new record?
Try it this way:
   DoCmd.OpenForm "yourForm", , , , acFormAdd
   Me!TrackingField.Recalc
   Me.Dirty = False      

or
DoCmd.OpenForm "yourForm", , , , acFormAdd
Me.Requery    
0
 

Author Comment

by:mamadouthiam
ID: 18825864
puppydogbuddy,


The form is already open.  User navigate to this form via the main switchboard.  Once there, there is a command to initiate a new record.  I would not want to automatically start a new record on open, b/c users also will view and edit on-going records on this form.

mama
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18825934
If form already open and this command is giving you error:
      DoCmd.GoToRecord , , acNewRec --> Error, object doesn't support
then you need to check form properties:
            Allow additons should be set to yes
            Allow edits should be set to yes
            Data Entry should be set to No.
If the above is not the answer, please post more of your code, starting with opening of form.
0
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 500 total points
ID: 18825988
mamdouthiam,
you can do it like this:
Me.AllowAdditions= True
Me.AllowEdits = True
Me.DataEntry = False
DoCmd.GoToRecord , , acNewRec
0
 

Author Comment

by:mamadouthiam
ID: 18826055
puppydogbuddy,

Still nothing.  All that happens is that the text in the tracking field (when it opens to the current record) disappears whereas the next number in the sequence should populate.

Can you supply the VB to requery the query behind this form?

mama
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18826094
You no longer get the error you were getting???
In response to your question>>>>>>>>>>>>Me.Requery
0
 

Author Comment

by:mamadouthiam
ID: 18826155
No, no error.

Does it have to do with the fact that the Tracking field was built?
Tracking: "Ourcompany-  " & tblFOIA!Number

This seems like a very simple thing and I think I have done this before without any trouble...

mama
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18826300
Not necessarily...does your menu form close when add form opens?
if menu form close, try Me.Requery; Me!Tracking.Requery......or ......Me.Recalc, or Me!Tracking.Recalc...... or
                    Me.Refresh......
If menu form stays open,
try fully qualified reference>>>>>>>>>>>Forms!YourMainForm.Requery
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18826372
Mama,
Just realized>>>>Tracking: "Ourcompany-  " & tblFOIA!Number
is not a numeric & can't be calculated.  Think you meant the following:
Tracking: = [Ourcompany] - [tblFOIA!Number]
 
0
 

Author Comment

by:mamadouthiam
ID: 18826486
I am such an a..

The problem was that I was starting a new record but I was,t entering any information and thus the record was not changing (and I guess no reason to add another new record when I clicked again)!

I now did this:

DoCmd.GoToRecord , , acNewRec
Me.Date_received.SetFocus
Me.Date_received = Now()

Automatically dropping the date in changes the record and everything is fine.  

Sorry I wasted your time.  Thanks so much for the help though!
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 18826552
Glad you got it resolved.  That is why it helps to provide as much info as possible.  Thanks for the points and grade.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question