Solved

Access - How to "show all records" after importing from a .csv?

Posted on 2009-07-16
18
458 Views
Last Modified: 2013-11-28
Hi -

I've got a Form with a button that imports .csv files.  The Import command button runs a macro, and it works fine.  However, after it imports the file to the underlying table, the form does not refresh the record count.  For example, if I have 20 records before the import, it says 1 of 20 at the bottom of the form.  

After importing 65 records, it still shows 1 of 20.  Also, even though a GoToControl action was executed, the cursor is nowhere on the form.

Then I click on the first field in the Detail section, and (either) press F5 (or click on Refresh All on the Ribbon), the record counter reads 1 0f 85.

Any ideas on:

1) getting the cursor back on a control
2) forcing a "refresh" of the record count


I've tried a few different things, but nothing seems to work.

I'm running Access 2007 on Windows XP, FWIW.

Thanks - ub  
0
Comment
Question by:Robert
  • 9
  • 5
  • 4
18 Comments
 
LVL 2

Expert Comment

by:diazluna
ID: 24872835
Add the following after the import:

Form.Requery()
Form.Refresh()

That'll do it.
0
 

Author Comment

by:Robert
ID: 24873066
diazluna,

Where do I put that in the Macro?  Sorry if I'm a bit obtuse on this, not used to jumping between Macro and VBA!

ub
0
 
LVL 2

Expert Comment

by:diazluna
ID: 24873087
You mentioned that you had a Form with a button that imports .csv files.  I am assuming you are calling your macro from here.  Step 2 run the 2 lines of code I gave you.
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:Robert
ID: 24874068
I don't know how to use the syntax you gave me.  I used the actions:

Requery
RunCommand (Refresh)

That's great - but the cursor is off in Neverland - I have no idea where it is.

I added GoToControl (fieldname), but... no cursor, blinking, block, or otherwise.

0
 
LVL 2

Expert Comment

by:diazluna
ID: 24874289
Use SetFocus()
0
 

Author Comment

by:Robert
ID: 24874519
How do I do that in a ***macro***?  
0
 
LVL 2

Accepted Solution

by:
diazluna earned 500 total points
ID: 24878792
RunCommand (Forms!Form.SetFocus)
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24880242
if you go to design view of your form. Click on the Import button. Open the properties sheet for the button. Go to the Events tab. Select the On_Click event and open the code.

After the call to the Macro (in the code), you can place a me.requery there. You do not need to add it to the Macro itself.

J
0
 

Author Comment

by:Robert
ID: 24880973
The RunCommand action would not accept the argument.

Please see attached.  It's a Macro, it isn't code.

On-Click-to-Macro.JPG
On-Click-Macro.JPG
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24881020
see that little ... button out to the right of the OnClick event option? Click on that

It will open the VBA window where you can add code.

J
0
 

Author Comment

by:Robert
ID: 24882613
I do see the [...] button.  But since I have a Macro, it only opens up the Macro.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24886301
inside the design view of the Macro, select Save AS from the menu.  Save your macro as code. Now when you click the ... it will open you up to the VBA window where you can do your requery.
J
0
 

Author Comment

by:Robert
ID: 24890408
So the Macro actions just don't work right?
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24897222
I suppose we can try.

Before you try your requery step, insert a step to select the object

SelectObject "ype = Form, ObjectName = "FormName" InDatabaseWindow = No

J
0
 

Author Comment

by:Robert
ID: 24910639
I did, and it still did not return focus to the torm.  No cursor, no focus.  Pressing Enter, Tab, Esc does nothing.
0
 

Author Comment

by:Robert
ID: 24982425
So - any other suggestions?
0
 
LVL 2

Expert Comment

by:diazluna
ID: 24982506
No more without seeing the actual database.  You have to give me some credit for the Refresh issue. :)
0
 

Author Comment

by:Robert
ID: 24985192
diazluna,

You've got 250 pts coming at you.  

ub
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

840 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