Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 

Forums     

Microsoft Access Forum
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

 
This forum is for the discussion of Microsoft Access.

Access is my personal specialty. Have questions? Comments? Want to discuss how to do something? Post it here. Also, I get a LOT of questions sent to me in Email from people around the world. I'll post the interesting ones in here. Feel free to comment on them.

Click Here To Subscribe to this forum and receive an email update whenever new posts are added, just scroll down to the bottom of this page and enter your email address in the comment form.

Permanent Link
Keywords: microsoft access forum
Post New Topic

Read string concatenation by John M @ 6/8/2018
I am having a small problem. I am trying to use a list box to show a list of forms, when you select a form from the list it will get the Record Source from that form. Here is the code:
Private Sub List0_AfterUpdate()

    Dim stFrmName As String
    Dim stRECSorce As String
    Dim myName As String
        
    stFrmName = Me!List0.Column(1)
    DoCmd.OpenForm stFrmName
    myName = Forms!clients.RecordSource
      
    'myName = (Forms! & stFrmName & .RecordSource)
    'DoCmd.Close acForm, stFrmName
    MsgBox "The information is " & stFrmName & " " & myName
End Sub
in the first myName line I entered it manually works fine. But in the second myName I get on the msgbox "Clients" and then the string Forms!Clients.RecordSource.  What am I doing wrong? I have tried several forms of string concatenation the way I understand it. Need a point in the right direction.
Show Just This Thread        Post Reply
Read String Concatenation by Brent @ 3/6/2012
I am sorry about being a pest, The biggest problem with doing this SQL and VBA is syntax I dont understand all the quotes and & and _ and I feel it really is dragging me down at getting a grasp of access. what I have is this

****SQL STATEMENT***

EntryList.RecordSource = "SELECT * FROM ClockT WHERE WorkDay" = Forms!ClockF!WorkDay And JobNumber = " Forms!ClockF!JobNumberBox ORDER BY StartTime"

******END CODE****

I can not get this to work.


Reply from Richard Rost:

Try this:

EntryList.RecordSource = "SELECT * FROM ClockT WHERE WorkDay=" & Forms!ClockF!WorkDay & " AND JobNumber=" & Forms!ClockF!JobNumberBox & " ORDER BY StartTime"

Now, if WorkDay is a DATE value, you need # signs:

EntryList.RecordSource = "SELECT * FROM ClockT WHERE WorkDay=#" & Forms!ClockF!WorkDay & "# AND JobNumber=" & Forms!ClockF!JobNumberBox & " ORDER BY StartTime"

If it's a TEXT value, you need more quotes:

EntryList.RecordSource = "SELECT * FROM ClockT WHERE WorkDay='" & Forms!ClockF!WorkDay & "' AND JobNumber=" & Forms!ClockF!JobNumberBox & " ORDER BY StartTime"

Review my lesson on STRING CONCATENATION. If you want to add a form value to a LITERAL string, it looks like this:

X = "Hello " & FieldName

The & character just adds (concatenates) two strings together - whether they're literal string values inside of quotes, or a field value.

The _ is just a line continuation character. You don't HAVE to use it, it just makes your code more readable (without having to scroll to the left):

X = "This is a long line. I can use the line " & _
     "continuation character to break it up."

Hope this helps.
Show Just This Thread        Post Reply

Collapse All Topics

 

Post Your Comments or Subscribe
    If you would like to be notified of new posts on this forum,
    just enter your email address below. It will be kept private.
 
If you just want to subscribe to get email updates when this forum is updated, then enter your name and email address and check the Notify Me box below. If you would optionally like to add your comments below to be posted, they are welcome.
 
  Your Name:  Required
  Your Email:  NOT Public
  Subject:
  Comments:

 

Sorry about this step. It's just to keep the spam bots away:
  Verify: What is 3+7:
  
  Notify me when the this forum is updated
  Remember Me for my next comments
  
 
 
Please do not use this form for Customer Service inquiries! If you have questions about your account, shipping info, courses you've ordered, need passwords, etc. please use the Customer Service Center instead.

I value your comments. They will be displayed on this page (above). Your name will be displayed, but your email address will not be.
As always, I promise to never give away your personal information to anyone else, ever.

NOTE: If you don't leave your name and email address, DON'T expect a reply. I can't promise a personal reply to everyone who posts here. I TRY my best, but I cannot guarantee it. If you don't leave your real name and email address, I won't even bother. I usually just hit DELETE. -Richard

 

 

You may want to read these articles from the 599CD News:

11/20/2018Microsoft Access Developer 12
8/25/2018NEW: Access Dev 9, 10, 11
8/25/2018Microsoft Access Developer 11
8/25/2018Microsoft Access Developer 10
8/25/2018Microsoft Access Developer 9
8/23/2018Access Dev 11 is ONLINE
8/17/2018Access Dev 10 is ONLINE
8/15/2018Access Tip: Search Form
8/15/2018Access Tip: Locked v. Enabled
8/15/2018Access Dev 9 is ONLINE
 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP