473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Pass-through query as rowsource for combo box

Is it possible to set (using VBA) the rowsource for a combo box but
have that rowsource come from a pass-through query.

I can obviously manually go into the rowsource property and define the
query and even set up the odbc string, but if i want to set this using
VBA i cannot see how to do this.

I know i can set forms!frm_test!combobox.rowsource to the SQL but that
does not allow me to set the odbc for the passthrough element.

Is it just not possible?

Any thoughts woudl be gratefully received.

Thanks.

Jun 12 '07 #1
5 11485
OK, i've discovered that i should be setting the RecordSet property as
I can define a recordset using a query def object and then assign the
resultset to the control.

I think that is the best answer - any other comments or ideas?

Cheers,

On 12 Jun, 10:19, dkintheuk <dkinth...@googlemail.comwrote:
Is it possible to set (using VBA) the rowsource for a combo box but
have that rowsource come from a pass-through query.

I can obviously manually go into the rowsource property and define the
query and even set up the odbc string, but if i want to set this using
VBA i cannot see how to do this.

I know i can set forms!frm_test!combobox.rowsource to the SQL but that
does not allow me to set the odbc for the passthrough element.

Is it just not possible?

Any thoughts woudl be gratefully received.

Thanks.

Jun 12 '07 #2
Okay, that didn't work exactly as i planned - it seems that once you
have usde querydef to define the query you only have to refer to the
query as the rowsource by name rather than try to create a
recordsource and make that the recordsource of the control.

Lesson learned = keep it simple.

On 12 Jun, 12:31, dkintheuk <dkinth...@googlemail.comwrote:
OK, i've discovered that i should be setting the RecordSet property as
I can define a recordset using a query def object and then assign the
resultset to the control.

I think that is the best answer - any other comments or ideas?

Cheers,

On 12 Jun, 10:19, dkintheuk <dkinth...@googlemail.comwrote:
Is it possible to set (using VBA) the rowsource for a combo box but
have that rowsource come from a pass-through query.
I can obviously manually go into the rowsource property and define the
query and even set up the odbc string, but if i want to set this using
VBA i cannot see how to do this.
I know i can set forms!frm_test!combobox.rowsource to the SQL but that
does not allow me to set the odbc for the passthrough element.
Is it just not possible?
Any thoughts woudl be gratefully received.
Thanks.- Hide quoted text -

- Show quoted text -

Jun 12 '07 #3
dkintheuk wrote:
Is it possible to set (using VBA) the rowsource for a combo box but
have that rowsource come from a pass-through query.
Here's what I do. All the code here uses David Fenton's dblocal
function which keeps the currentdb database object open throughout the
application. If you don't use this, where you see "dblocal", you'll
need to dim a DAO.database object

The following is the code from a form on open event (or could be used in
the combo box got focus event if the results are goiing to vary a lot
depending on the value of other combos and controls). It populates a
combo box cboAcctCredit with a pass through query. I'm using Oracle.

Sub sPopulateCombo()

dim strS as string

'Populate cboacctcredit - make PTQ of credit accounts
strS = "Select "
strS = strS & "cst_code ""TMA Acct Code"", "
strS = strS & "cst_name ""TMA Acct Name"", cst_active ""Active"" "
strS = strS & "from tma.f_accounts "
strS = strS & "where "
strS = strS & "cst_ay_fk in "
strS = strS & "(select mbc_tma_credit_acct_type_fk "
strS = strS & "from tma.mun_ban_constant) "
strS = strS & "order by 1"
'Use sCreatePT sub (code follows) to create PTQ
sCreatePT strS, "qryRulesTmaCreditAccts"
'Assign the PTQ to the rowsource of the combo box
Me.cboAcctCredit.RowSource = "qryRulesTmaCreditAccts"

End Sub

Sub sCreatePT(strSql As String, strQryName As String, _
Optional strConnect As String)

'Takes an SQL string (strSql) and a query name (strQryName) and either
'creates a new PT query or, if
'it exists already, changes the SQL string
'
'strSql is the Oracle select statement
'strQryName is the name of the PTQ to be saved in the mdb/e
'strConnect is the optional connect string that differs from the
' "default" connect string used here
Dim qdf1 As DAO.QueryDef
Dim booFound As Boolean

On Error GoTo Err_Proc

dbLocal.QueryDefs.Refresh
booFound = False

'dblocal - see email notes
For Each qdf1 In dbLocal.QueryDefs
If qdf1.Name = strQryName Then
booFound = True
Exit For
End If
Next

If booFound = False Then 'querydef does not exist, so create it
Set qdf1 = dbLocal.CreateQueryDef(strQryName)
Else 'already exists
Set qdf1 = dbLocal.QueryDefs(strQryName)
End If

'Now assign characteristics
'The connect string here is a constant declared in a standard
' module as Public Const cTmarConnect = "<connect string>"
If strConnect = "" Then strConnect = cTmarConnect 'default connect
string

With qdf1
.Connect = strConnect
.SQL = strSql
.ReturnsRecords = True
End With

Exit_Proc:
On Error Resume Next 'use brute force to close
qdf1.Close
Set qdf1 = Nothing
On Error GoTo 0
Exit Sub
Err_Proc:
Select Case Err.Number
'Case 3011 '
Case Else
'My own custom error handling routine that
' deals with Oracle errors
fError "Mod_Access_Objects", "sCreatePT"
Resume Exit_Proc
End Select

End Sub


--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Jun 12 '07 #4
On 12 Jun, 18:29, Tim Marshall <TIM...@PurplePandaChasers.Moertherium>
wrote:
dkintheuk wrote:
Is it possible to set (using VBA) the rowsource for a combo box but
have that rowsource come from a pass-through query.

Here's what I do. All the code here uses David Fenton's dblocal
function which keeps the currentdb database object open throughout the
application. If you don't use this, where you see "dblocal", you'll
need to dim a DAO.database object

The following is the code from a form on open event (or could be used in
the combo box got focus event if the results are goiing to vary a lot
depending on the value of other combos and controls). It populates a
combo box cboAcctCredit with a pass through query. I'm using Oracle.

Sub sPopulateCombo()

dim strS as string

'Populate cboacctcredit - make PTQ of credit accounts
strS = "Select "
strS = strS & "cst_code ""TMA Acct Code"", "
strS = strS & "cst_name ""TMA Acct Name"", cst_active ""Active"" "
strS = strS & "from tma.f_accounts "
strS = strS & "where "
strS = strS & "cst_ay_fk in "
strS = strS & "(select mbc_tma_credit_acct_type_fk "
strS = strS & "from tma.mun_ban_constant) "
strS = strS & "order by 1"
'Use sCreatePT sub (code follows) to create PTQ
sCreatePT strS, "qryRulesTmaCreditAccts"
'Assign the PTQ to the rowsource of the combo box
Me.cboAcctCredit.RowSource = "qryRulesTmaCreditAccts"

End Sub

Sub sCreatePT(strSql As String, strQryName As String, _
Optional strConnect As String)

'Takes an SQL string (strSql) and a query name (strQryName) and either
'creates a new PT query or, if
'it exists already, changes the SQL string
'
'strSql is the Oracle select statement
'strQryName is the name of the PTQ to be saved in the mdb/e
'strConnect is the optional connect string that differs from the
' "default" connect string used here

Dim qdf1 As DAO.QueryDef
Dim booFound As Boolean

On Error GoTo Err_Proc

dbLocal.QueryDefs.Refresh
booFound = False

'dblocal - see email notes
For Each qdf1 In dbLocal.QueryDefs
If qdf1.Name = strQryName Then
booFound = True
Exit For
End If
Next

If booFound = False Then 'querydef does not exist, so create it
Set qdf1 = dbLocal.CreateQueryDef(strQryName)
Else 'already exists
Set qdf1 = dbLocal.QueryDefs(strQryName)
End If

'Now assign characteristics
'The connect string here is a constant declared in a standard
' module as Public Const cTmarConnect = "<connect string>"
If strConnect = "" Then strConnect = cTmarConnect 'default connect
string

With qdf1
.Connect = strConnect
.SQL = strSql
.ReturnsRecords = True
End With

Exit_Proc:
On Error Resume Next 'use brute force to close
qdf1.Close
Set qdf1 = Nothing
On Error GoTo 0
Exit Sub
Err_Proc:
Select Case Err.Number
'Case 3011 '
Case Else
'My own custom error handling routine that
' deals with Oracle errors
fError "Mod_Access_Objects", "sCreatePT"
Resume Exit_Proc
End Select

End Sub

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
That's nice pal, cheers for the input - i have found some interesting
things about the handling of ODBC that make it a little awkward to do
what i want - specifically because the destination databse is Sybase
(urk!).

That has helped me a great deal in refining what i had created.

Cheers pal.

Jun 13 '07 #5
dkintheuk wrote:
That's nice pal, cheers for the input - i have found some interesting
things about the handling of ODBC that make it a little awkward to do
what i want - specifically because the destination databse is Sybase
(urk!).
Glad it helped. I find that with apps based on pass through queries I
end up with no table links in the table tab of the mdb database window,
but tons and tons of PTQs in the query window.

As I mentioned, I usually store the connect string as a constant, but
this makes it difficult to hide the database password - even an mde can
be opened in notepad or some text reader and you can find the connect
string in plain text. Nasty, if you include the user password in the
string so that your users don't need to enter it. In my case, since
most of my apps are reporting on existing data, I just use a DSN that
has no writing privileges.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Jun 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
3
by: QQ | last post by:
I have one integer array int A; I need to pass this array into a function and evaluate this array in this function how should I pass? Is it fine? void test(int *a)
4
by: kinaxx | last post by:
Hello, now I'm learning progamming language in university. but i have some question. in textbook. says there are four passing Mechanism 1) pass by value (inother words : call by value) 2)...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
15
by: ramif | last post by:
Does call by reference principle apply to pointers?? Is there a way to pass pointers (by reference) to functions? Here is my code: #include <stdio.h> #include <stdlib.h>
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.