PC Review


Reply
Thread Tools Rate Thread

dinamic query

 
 
yaniv d
Guest
Posts: n/a
 
      14th May 2006
hello all,
does anyone know how to cut query fields dinamicly through VBA?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      14th May 2006
What exactly do you mean by "cut query fields"? Can you give an example of
what you are trying to accomplish?

Also, the term is dynamic, not dinamic.


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"yaniv d" wrote:

> hello all,
> does anyone know how to cut query fields dinamicly through VBA?

 
Reply With Quote
 
yaniv d
Guest
Posts: n/a
 
      14th May 2006
hi
i mean that i want to remove or add fields in the query with vba or in
another way

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      15th May 2006
Try this for an existing query named "qryTest", which is based on a table
named "My Table", with fields named "Field1", "Field2" and "Field3". You
might, for example, have an option group on a form with buttons that allowed
you to specify custom sort orders.


Option Compare Database
Option Explicit

Sub BuildQuery(intSortOrder As Integer)
On Error GoTo ProcError

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryTest")

Select Case intSortOrder
Case 1
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field1"
Case 2
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field2"
Case Else
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field3"
End Select

qdf.SQL = strSQL


ExitProc:
On Error Resume Next
Set qdf = Nothing
db.Close: Set db = Nothing
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure BuildQuery..."
Resume ExitProc
End Sub


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"yaniv d" wrote:

> hi
> i mean that i want to remove or add fields in the query with vba or in
> another way

 
Reply With Quote
 
yaniv d
Guest
Posts: n/a
 
      15th May 2006
can you send me the same code but in ADO or ADODB?

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      15th May 2006
Although I'll be the first to admit that ADO is not one of my stronger areas,
try this version:


Sub EditQueryUsingADO(intSortOrder As Integer)
On Error GoTo ProcError

' Early binding
' Note: Requires references set to
' "Microsoft ActiveX Data Objects 2.x Library" and
' "Microsoft ADO Ext. 2.x for DDL and Security"

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim cat As New ADOX.Catalog
Dim view As ADOX.view
Dim strSQL As String

Set conn = Application.CurrentProject.Connection
Set cat = New ADOX.Catalog


Select Case intSortOrder
Case 1
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field1"
Case 2
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field2"
Case Else
strSQL = "SELECT Field1, Field2, Field3 FROM [My Table] " _
& "ORDER BY Field3"
End Select


' Open the Catalog
Set cat.ActiveConnection = conn

Set view = cat.Views("qryTest")
Set cmd = view.Command

cmd.CommandText = strSQL
Set view.Command = cmd


ExitProc:
'Clean up
On Error Resume Next
Set cmd = Nothing: Set view = Nothing: Set cat = Nothing
conn.Close: Set conn = Nothing
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure EditQueryUsingADO..."
Resume ExitProc
End Sub



Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"yaniv d" wrote:

> can you send me the same code but in ADO or ADODB?

 
Reply With Quote
 
yaniv d
Guest
Posts: n/a
 
      15th May 2006
thanks,
i decided to do it use combo box and by them to filter,
my question is do you think there is an option to compare between to
table and update them in the current FORM?

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      15th May 2006
Repost as a new question.

Please try to explain exactly what you want to accomplish, because I'm back
to not understanding what it is that you are wanting to do. In any case, I
believe the scope has changed enough that this warrants a new thread.


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"yaniv d" wrote:

> thanks,
> i decided to do it use combo box and by them to filter,
> my question is do you think there is an option to compare between to
> table and update them in the current FORM?

 
Reply With Quote
 
yaniv d
Guest
Posts: n/a
 
      15th May 2006
i need to build a form that will implement groups by grouping
level,every group wil be implementing the sum and avarage of some
paramenters coming from a query.
i need 2 things,:
1.to implement a dinamic grouping level
for example:
country->location->job category
or
country->grade->job category
or
country->location->grade

those are just for example i need to perform more complex grouping then
this

2.i need to save the values that will be added to the form in a table
that when the form will be loaded again it will bring the new values
that entered the last time

thats it in brief

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dinamic remote IP Davide Windows XP Work Remotely 3 2nd Jul 2009 06:05 PM
Dinamic images Damir Microsoft ASP .NET 0 6th May 2005 08:02 AM
Dinamic Query Linked to a Dynamic Report =?Utf-8?B?QWxleA==?= Microsoft Access Queries 1 28th Nov 2004 12:26 AM
MFC dinamic creation Rajko Microsoft VC .NET 0 16th May 2004 10:41 AM
Dinamic query for alfabetical selection WebRaster Microsoft Access Queries 1 17th Nov 2003 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.