I am going through a migration from Access mdb to SQL also, and a lot of my
queries had the type of form-based criteria that you mention. One solution I
have used is to remove all references to form-based criteria in the SQL Views
(you may have to re-write all the Access queries as Views), and specify the
criteria in the VBA statement that is executed when the On Click event of a
control button is initiated by the user. The event runs the Open Form
instruction, and the form is based on the view-- apparently, you can't
specify criteria using Open View-- correct me if I'm wrong, everyone-- but
with Open Form you can, so I just make a simple datasheet form based on the
view.
SO... if you have an Access query that used to refer to a field on a form
(which SQL doesn't know exists) such as your [frms]![frm_Name]![region], in
the VBA procedure that calls the new form you would say something like:
stLinkCriteria = "[Region]=" & "'" & Me![region] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria, acFormReadOnly
On a RELATED note, I am having trouble with one of my queries, though. In
Access it reads a name on a form, and when the user hits a control button,
the query runs and shows all names that begin with the same 3 letters as the
name on the form. IN Access,, the Last Name field has this criteria:
Like Left([Forms]![csrF]![IntReqLN],3) & "*"
I can get the corresponding SQL view to open with an exact match of the last
names like this:
stLinkCriteria = "[Lname]=" & "'" & Me![Last Name] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria, acFormReadOnly
But I haven't been able to figure out how to get the match of just the first
three letters to work.. the "Like Left" part. Can anyone help? Thanks!
What are you going to do with the query?
Use it as the Record Source for a form or report? Then, investigate the InputParameters Property for forms/reports - "You can use
the InputParameters property to specify or determine the input parameters that are passed to a SQL statement in the RecordSource
property of a form or report or a stored procedure when used as the record source within a Microsoft Access project (.adp).
Read/write String."
Also, you should know that if you use a parameterized stored procedure as the record source for a subform of form myMasterForm, that
if any of the form controls "happen" to be named identically to any of the SPs parameters, the value of the form variable will be
used "magically". This might take care of some of your use cases...???
--Malcolm Cook
Alan said:
I have done some Access work in the past, but keeping an Access Back-end. I recently had to up-size to SQL for an ADP file without
much research or preparation. I've been able to pass parameters to queries and reports from a form by using
=[forms]![frm_Name]![region] and the like. But since converting to ADP format, I've not been able to figure out the new thought
process.
I've spent an hour in Google and in help and have dound some cool things, but none relevant to this situation.
Thoughts or links?
Many thanks
~alan