468,790 Members | 1,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,790 developers. It's quick & easy.

Want to create VBA to create a button which will go to the relevant line in a linked database for a client

7 Nibble
I'm trying to write VBA to create a button which will go to the relevant line in a linked database for a specific client. First I need to have VBA that IDs when the client name in the report matches that in the linked table.

This is what I have so far.
DoCmd.OpenForm "Clients with matches Full Report",View:=acFormsDS, ,WhereCondition "FinCoaching Enrollment File 2"!.Client__Name = " & "Client with matches Full Report"!Client_Name, ,

When it gets to Wherecondition it says it was expecting a parameter.

Thanks.
Jun 18 '21 #1
9 3617
NeoPa
32,132 Expert Mod 16PB
You have the wrong format for the call of DoCmd.OpenForm. Check with the documentation for the correct parameters to use but one thing you certainly cannot do is to mix up positional parameters with named ones. If you want to use named parameters, and I do recommend that where possible, then the format is :
Expand|Select|Wrap|Line Numbers
  1. NameOfParameter:=Value
A WhereCondition parameter must be a string value that is correctly formatted as a SQL WHERE clause.
Jun 18 '21 #2
hwsilver
7 Nibble
THanks, NeoPa.
Can a table and variable appear like this? "FinCoaching Enrollment File 2"!.Client__Name?
Jun 20 '21 #3
NeoPa
32,132 Expert Mod 16PB
Hi there.

No. That wouldn't be correct syntax.

To be fair, I've very little idea what you're asking as you give no context clues, but I can say with certainty that whether your question is about SQL or VBA then the answer is definitely "No". Otherwise, you may want to consider making your comments clearer so they make sense to those of us trying to understand you.
Jun 21 '21 #4
hwsilver
7 Nibble
I want to reference a table named "FinCoaching Enrollment File 2" that contains a variable named Client__Name. One source said to use quotes when a file name has spaces.

What is the correct way to do this in VBA?

Thanks.
Jun 28 '21 #5
NeoPa
32,132 Expert Mod 16PB
VBA doesn't reference Table Fields directly. I say Fields because Tables don't have Variables and I expect that's what you're trying to say.

I was rather hoping you'd do a little bit of work before replying to ensure what you ask makes sense this time, rather than leaving it up to us again to guess what it is you're trying (but not very hard) to express. All I see is a simple repetition of the same question that was so poor before. Nevertheless, for now, I will attempt to answer as well as I can and guess what you mean.

So then, VBA is an Access (Office+) language that works with many entities in many different ways. It doesn't give access to data (Tables, Queries, Fields, etc) natively. As such your question doesn't make sense as it stands.

You can access data within Tables by Field (Bearing in mind obviously you also need to ensure you have the correct record selected.) either by using DLookup() or by using Recordset coding in your VBA.

Generally speaking, and this is more for SQL than VBA though they can overlap here a bit, when dealing with items whose names contain spaces and/or other characters that may otherwise be treated as delimiters you should enclose them in brackets []. Thus, when referencing the table you would use [FinCoaching Enrollment File 2].

It is generally considered wiser not to use such characters in names but we don't always control what we have to work with so it helps to know how to handle them when forced to.
HWSilver:
One source said to use quotes when a file name has spaces.
That may be true, but I doubt they were talking about what you're asking about. I know of no situation where quotes, of either type (' or ") would be of any help in this regard at all.
Jun 29 '21 #6
twinnyfo
3,652 Expert Mod 2GB
I would do this:

Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2.  
  3. strWhere = "[FinCoaching Enrollment File 2].Client_Name = " & Me.Client_Name
  4.  
  5. Call DoCmd.OpenForm( _
  6.     FormName:="Clients with matches Full Report", _
  7.     View:=acFormsDS, _
  8.     WhereCondition:=strWhere)
This assumes Client_Name (with only one underscore) is a Field in the referenced Table and a field available in the Form/Report from which you are calling this code.

Hope that hepps!
Jun 29 '21 #7
NeoPa
32,132 Expert Mod 16PB
Tsk tsk Twinny. I hope you aren't assuming that Me.Client_Name takes numeric data :-(

PS. No sneakily fixing it before claiming innocence!
Jun 29 '21 #8
twinnyfo
3,652 Expert Mod 2GB
True, true, NeoPa! Faulty assumption on my part, but hopefully the suggestion points OP in the right direction.

I should have learned my lessons by now—I’m just so accustomed to numerical values. Here’s the text version:

Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2.  
  3. strWhere = "[FinCoaching Enrollment File 2].Client_Name = '" & Me.Client_Name & "'"
  4.  
  5. Call DoCmd.OpenForm( _
  6.     FormName:="Clients with matches Full Report", _
  7.     View:=acFormsDS, _
  8.     WhereCondition:=strWhere)
Still don’t know fer sher if this is what OP is looking for.

Thanks for the hepp!
Jun 30 '21 #9
NeoPa
32,132 Expert Mod 16PB
True. It's hard to answer when people can't even ask the question properly. I guess throwing out examples might help in case one of them hits what they're actually looking for. They certainly don't hurt ;-)
Jun 30 '21 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by G rumpy O ld D uffer | last post: by
2 posts views Thread by Robert McGregor | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.