-
WSCecilia
AskWoody LoungerOkay, I realize that you don’t want an input mask, but now I’m asking you….What does this code do that an input mask doesn’t?
For example, if I use as my input mask LLLLL (or ?????), then the user must enter (at least) five letters. (AAAAA will require (aaaaa is entry optional) five letters or numbers, excluding symbols.) Isn’t that what you’re after? To prevent the user from entering anything but exactly what you want? What is the benefit to doing this in code?
Just curious,
Cecilia
-
WSCecilia
AskWoody LoungerWouldn’t an input mask restrict what the user can enter?
Do you mean a validation rule then? Are you looking for code that checks the last character entered and tests to see if it’s a valid entry?
Sorry, sign me
~~Confused -
WSCecilia
AskWoody LoungerDo you mean like an input mask?
If so, these are from Help:
L = Letter (A to Z, entry required).
? = Letter (A to Z, entry optional).You can enter the appropriate mask in the textbox’s Input Mask property.
-
WSCecilia
AskWoody LoungerHi Hans,
Yes, I did do that. I think the reference is Excel 8.0. Mostly, it works very nicely
Every so often I get an automation error and have to shut down Access and start over. It seems that bits of Excel get stuck here & there, but I can live with that.
Thanks again, both of you!
Cecilia
-
WSCecilia
AskWoody LoungerOf course! Here’s my code:
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
‘Open the New Template
Set xlBook = Excel.Application.Workbooks.Open(strExternalFile)
Set xlSheet = xlBook.Worksheets(“Access Data”)‘Paste the Recordset
With xlSheet
For lngColumn = 1 To rst.Fields.Count
.Cells(1, lngColumn).Value = rst.Fields(lngColumn – 1).Name
Next lngColumn
.Range(“A2”).CopyFromRecordset rst
End With -
WSCecilia
AskWoody LoungerThat’s funny, because CopyFromRecordset is working just fine in Access.
I’m already going from Access to Excel, at this point I can’t turn back now.
In any event, your code had what I needed:
For icols = 0 To rs.Fields.Count – 1
ws.Cells(1, icols + 1).Value = rs.Fields(icols).Name
NextI just changed the reference from ws to xlApp and it works fine.
Thanks!
Cecilia
-
WSCecilia
AskWoody LoungerActually, I just checked the code from your original post & it works just fine:
Function SubC(txt As String) As String
Dim x As Integer
Dim y As Integer‘Test for “-” in string
‘If “-” Exists, Return String to space prior to “-“, i.e., ABL- is ABL
‘If “-” does not exist, Get entire Trimmed StringFor x = 1 To Len(Trim(txt))
If Mid(txt, x, 1) = “-” Or Mid(txt, x, 1) = “*” Then ‘ Does “-” exist
y = x ‘Set Y = to placeholder of “-”
x = Len(txt) ‘Set X to end of loop
SubC = Left(txt, y – 1) ‘Return SubC Value
Exit For
Else:
SubC = Left(txt, x) ‘ If “-” does not exist, return trimmed txtEnd If
Next xEnd Function
-
WSCecilia
AskWoody LoungerThis is what happens when you’re in flat mode and everyone else is threaded, your mind becomes so boggled that you forget where you’re replying….
How about
If instr(strMyString,chr(42))>0 then strMyString=Left$(strMyString,instr(strMyString,chr(42))-1)
THere’s a list of Character Codes in Access Help.
Cecilia
-
WSCecilia
AskWoody LoungerOooh! I thought I had tried that, but evidently I had not. It works very nicely.
Thanks, Hans!
One back at you:
-
WSCecilia
AskWoody LoungerYou could always use chr(42) instead of “*”
If instr(strMyString,chr(42))>0 then strMyString=Left$(strMyString,instr(strMyString,chr(42))-1)
Look up Character Codes in Access Help.
-
WSCecilia
AskWoody LoungerAccess doesn’t like this line:
Set xlBook = xlApp.Workbooks.Open strExternalFileIt thinks it doesn’t need a file name at the end. I can’t seem to find a way to open a specific book that way, which _should_ be the way to do it?
Long explanation:
Basically, what I’m trying to do is this: my co has given me four weeks to design a reporting databases and build a gazillion reports from a transactional database that was built years ago and there are few people left that know a heck of a lot about it. The people in the dept that I am doing this for already have excel spreadsheets with their end reports, but to use them they use this horrible manual process of moving the data from iSQL and other stuff and massaging it this way and that. Since I don’t think I can both design an entire reporting database and all the reports in just four weeks, I’m going with the “good enough for now” approach and designing the reporting database and just filling the excel sheets until I have time to build proper Access reports.
So basically, my routine is supposed to copy an existing excel spreadsheet (sort of a template), name it a particular way, then fill it with appropriate data. This has to happen for about 12 separate spreadsheets (so far). Since the reports are already in the workbooks, I’m done. All I have to do is figure out how to save the data when the excel workbook isn’t passed to the user….
Cecilia
-
WSCecilia
AskWoody LoungerActually, if all he wants is to truncate, this should work quickly and easily, then there’s only two lines of code…
If instr(strMyString,”-“)>0 then strMyString=Left$(strMyString,instr(strMyString,”-“)-1)
If instr(strMyString,”*”)>0 then strMyString=Left$(strMyString,instr(strMyString,”*”)-1)Cecilia
(Sign me: jealous of those with nifty built in functions like Replace) -
WSCecilia
AskWoody LoungerPlease tell me…
This is available in 97???
Cecilia
-
WSCecilia
AskWoody LoungerHow about
If Mid(txt, x, 1) = “-” or Mid(txt,x,1)=”*”Here is what I do if I want to strip a character out of a string, you might want to modify it….
intPos = InStr(strMyString, “_”)
Do Until intPos = 0
strMyString = Left$(strMyString, intPos – 1) & ” ” & Mid$(strMyString, intPos + 1)
intPos = InStr(strMyString, “_”)
Loop -
WSCecilia
AskWoody LoungerHee hee, I thought I had too! (guess not enough, though) Just goes to show you that REBOOT really does work! *g*
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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
-
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
6 hours, 22 minutes ago -
Office apps read-only for family members
by
b
8 hours, 58 minutes ago -
Defunct domain for Microsoft account
by
CWBillow
5 hours, 50 minutes ago -
24H2??
by
CWBillow
1 hour ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
17 hours, 44 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
10 hours, 57 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
5 hours, 47 minutes ago -
two pages side by side land scape
by
marc
2 days, 6 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
2 days, 8 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
1 day, 11 hours ago -
Security Essentials or Defender?
by
MalcolmP
1 day, 14 hours ago -
April 2025 updates out
by
Susan Bradley
9 hours, 28 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
1 day, 7 hours ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
21 hours, 56 minutes ago -
Creating an Index in Word 365
by
CWBillow
2 days ago -
Coming at Word 365 and Table of Contents
by
CWBillow
12 hours, 31 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
3 days, 3 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
3 days, 7 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
3 days, 9 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
3 days, 7 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
3 days ago -
I installed Windows 11 24H2
by
Will Fastie
1 day, 6 hours ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
3 days, 12 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
5 hours, 56 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
3 days, 20 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
3 days, 5 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
3 days, 5 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
4 days, 13 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
4 days, 22 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
21 hours, 56 minutes ago
Recent blog posts
Key Links
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.