-
WSjohnhutchison
AskWoody LoungerYou move back to the first record each time you go through the loop.
You don’t need the .movelast and .movefirst within the Do Loop.
The Dim strOldNote as string line should occur before the loop starts so it only happens once. -
WSjohnhutchison
AskWoody LoungerHey All,
I’ve been googling and reading and I still can’t figure out how to simply assign a keyboard shortcut to run a VBA routine in Access 2010. This was a piece of cake in 2003 with AutoKeys macro.
I am not aware of anything changing with this from 2003. I still just use an AutoKeys macro like I used to. (But I never use accdb format. Does that affect things?)
-
WSjohnhutchison
AskWoody LoungerDoesn’t this do the same?
Environ$(“Username”)I think you are right Patt.
-
WSjohnhutchison
AskWoody LoungerWhy not use a text field for the account number?
I agree that a text field is the right solution.
But Nancy has said: “My problem is that we have the account number field everywhere in multiple databases, tables, queries and reports. It is a key field for us. Changing it everywhere would be a challenge.” -
WSjohnhutchison
AskWoody LoungerYou are correct about CurrentUser.
Here is another function that does what you want.
Code:Public Function NetUser() As String Dim strName As String Dim strUserName As String Dim intPos As Integer strName = vbNullString strUserName = Space(25) If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then intPos = InStr(strUserName, vbNullChar) NetUser = Left(strUserName, intPos – 1) Else NetUser = “-unknown-” End If End Function
But you need to put this at the top of a general Module
Code:Declare Function GetUserName Lib “advapi32.dll” Alias “GetUserNameA” (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function WNetGetUser Lib “mpr.dll” Alias “WNetGetUserA” _ (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
-
WSjohnhutchison
AskWoody LoungerKill strFileFullName
I usually rename the file and/or move it to another folder rather than just delete it. But I agree that just leaving the file there is an invitation to import it again.
-
WSjohnhutchison
AskWoody LoungerIf you look on the Property Sheet, at the properties of the form itself, on the Data tab, there are properties that control just this.
I would think that you don’t want users to create new records either (as you are just reusing existing records)
30480-AllowDeletions -
WSjohnhutchison
AskWoody LoungerAs for multiple files and rewriting code will the outcome be any different than what it is now?
If properly rewritten it could handle multiple files and import them.
Here is a version that works (I think).
Code:Private Sub cmdImportexcel_Click() Dim i As Integer Dim zXLFPath As String Dim zXLFName As String Dim iFileType As Integer ‘Requires reference to Microsoft Office 14.0 Object Library Office 2010. ‘Note: Returns a fully qualified filename, e.g. d:pathfilename.ext Dim fDialog As Office.FileDialog Dim varFile As Variant Dim zCurDir As String ‘Set up the File Dialog. Set fDialog = Application.FileDialog(msoFileDialogFilePicker) With fDialog ‘Allow user to make multiple selections in dialog box .AllowMultiSelect = True .Title = “Please select the file to import” ‘Clear out the current filters, and add your own. .Filters.Clear .Filters.Add “Excel 2003”, “*.xls” .Filters.Add “Access 2007-10”, “*.xlsx” ‘Set the initial directory using passed argument string .InitialFileName = “D:” ‘Show the dialog box. If the .Show method returns True, the ‘user picked a file. If the .Show method returns ‘False, the user clicked Cancel. If .Show = True Then For i = 1 To .SelectedItems.Count zXLFPath = .SelectedItems(i) Debug.Print zXLFPath If UCase(Right(zXLFPath, 1)) = “X” Then iFileType = acSpreadsheetTypeExcel12Xml Else iFileType = acSpreadsheetTypeExcel12 End If DoCmd.TransferSpreadsheet acImport, iFileType, “BridesDB”, zXLFPath, True Next i End If End With End Sub
This code brings the FileDialog (that was previously a separate function ) back into the sub. Not that there was anything wrng with using a separate function, but I found the multi file easier to handle this way.
-
WSjohnhutchison
AskWoody LoungerYou are right that changing to AllowMultiselect=true allows you to select multiple files, but
PickFileDialog = .SelectedItems(1) takes the first of the selected files and returns it.
To work with multiple files would require the function code to be rewritten to return an array of files, which would then need to be imported one at a time using a loop.
-
WSjohnhutchison
AskWoody LoungerThe code tries to deal with this by having the FileDialog return Exit if you click Cancel.
Code:If .Show = True Then cmdFileDialog = .SelectedItems(1) Else cmdFileDialog = “EXIT” End If
But the subsequent code seems to add a path and an extension to that and treat it as a filename, which it can’t then find.
Try replacing:
If Trim(UCase(zXLFName)) = “EXIT” Then Exit Sub
with
If Dir(zXLFPath) “” Then
then add an End IF after the DoCmd.TransferSpreadsheet line.
-
WSjohnhutchison
AskWoody LoungerDo you even see the File Dialog?
Does it help if you make the change I showed in red? -
WSjohnhutchison
AskWoody LoungerI just tried this using RG’s code with the FileDialog and I needed to make a change to the PickFileDialog function as below:
Code:[COLOR=#ff0000]PickFileDialog[/COLOR] = .SelectedItems(1) [COLOR=#ff0000]PickFileDialog[/COLOR] = “EXIT” instead of [FONT font=monospace][/FONT]cmdFileDialog in both cases
And this line needed to be changed, to a folder I have.
zXLFPath = PickFileDialog(“G:BEKDocsExcelArchives”)This line worked as is, because if the table does not exist it just creates it.
DoCmd.TransferSpreadsheet acImport, iFileType, “BridesDB”, zXLFPath, TrueWhen you say it “bombs” can you tell us more about what happens? Do you get any errors or messages?
-
WSjohnhutchison
AskWoody LoungerTry some code like this, behind a button
Code:Me.RecordsetClone.FindFirst “isNull(Title)” Me.Bookmark = Me.RecordsetClone.Bookmark
This assumes the current form has access to al the records.
First, of course, depends on the order they are in. But I don’t suppose it matters much which one is found, as long as you find one. -
WSjohnhutchison
AskWoody LoungerThat makes it even worse. You can only use DateDiff with Dates.
There is a CDate function that will convert things to Dates but you have to be sure that what you have is recognisable as a Date. With a text field that is hard to guarantee. -
WSjohnhutchison
AskWoody LoungerFieldNo5 ReportTime Text (9.50AM on daily basis as default )
FieldNo6 ReportedAt Test Time when actually the employee reports for dutyAs I see it you have Reporttime as Text , and REportedAt as a Date.
You can’t calculate a DateDiff between a text field and a Date field.Is there a reason that REportTime is Text?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Discover the Best AI Tools for Everything
by
Alex5723
6 hours, 7 minutes ago -
Edge Seems To Be Gaining Weight
by
bbearren
53 minutes ago -
Rufus is available from the MSFT Store
by
PL1
17 hours, 5 minutes ago -
Microsoft : Ending USB-C® Port Confusion
by
Alex5723
19 hours, 14 minutes ago -
KB5061768 update for Intel vPro processor
by
drmark
1 hour, 39 minutes ago -
Outlook 365 classic has exhausted all shared resources
by
drmark
17 hours, 25 minutes ago -
My Simple Word 2010 Macro Is Not Working
by
mbennett555
15 hours ago -
Office gets current release
by
Susan Bradley
17 hours, 37 minutes ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
2 days, 7 hours ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
1 day, 16 hours ago -
Stop the OneDrive defaults
by
CWBillow
2 days, 8 hours ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
2 days, 18 hours ago -
X Suspends Encrypted DMs
by
Alex5723
2 days, 20 hours ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
2 days, 20 hours ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
2 days, 21 hours ago -
OpenAI model sabotages shutdown code
by
Cybertooth
2 days, 22 hours ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
2 days, 10 hours ago -
Enabling Secureboot
by
ITguy
2 days, 17 hours ago -
Windows hosting exposes additional bugs
by
Susan Bradley
3 days, 6 hours ago -
No more rounded corners??
by
CWBillow
3 days, 1 hour ago -
Android 15 and IPV6
by
Win7and10
2 days, 15 hours ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
3 days, 18 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
3 days, 21 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
3 days, 15 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
4 days, 4 hours ago -
May preview updates
by
Susan Bradley
3 days, 15 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
3 days, 7 hours ago -
Just got this pop-up page while browsing
by
Alex5723
3 days, 20 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
3 days, 17 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
2 days, 19 hours ago
Recent blog posts
Key Links
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.