Solved

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

Posted on 2009-07-16
18
456 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now