Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-30
15
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

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.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

730 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