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
Solved

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

Posted on 2007-03-30
15
279 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

792 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