-
Jun 18th, 2005, 01:03 AM
#1
Thread Starter
Addicted Member
how to call function query in access using command button
hi guys is there any codes to call query function using command button or all i have to do is only to set the properties of the command button?
thanks in advance
-
Jun 18th, 2005, 07:17 AM
#2
Re: how to call function query in access using command button
Originally Posted by ayahnabunda
hi guys is there any codes to call query function using command button or all i have to do is only to set the properties of the command button?
thanks in advance
in Access or from VB?
From Access:
VB Code:
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim stDocName As String
stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command10_Click:
Exit Sub
Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End Sub
If you want to run it from VB, I'll have to research that to see if it is possible, but I know RobDog888 knows if this is possible or not.
Last edited by Mark Gambo; Jun 18th, 2005 at 07:20 AM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jun 18th, 2005, 07:32 AM
#3
Re: how to call function query in access using command button
What was I thinking, instead of running as Access Query by using Access why not execute the query via ADO from VB6:
VB Code:
Option Explicit
Private strDataBaseName As String
Private strDBCursorType As String
Private strDBLockType As String
Private strDBOptions As String
Private rs As ADODB.Recordset
Private cn As ADODB.Connection
Private strSQL As String
Private Sub Command1_Click()
Dim b as Long
On Error GoTo Command1_Click_Error
Me.Command1.Enabled = False
strDBCursorType = adOpenDynamic 'CursorType
strDBLockType = adLockOptimistic 'LockType
strDBOptions = adCmdText 'Options
Set cn = New ADODB.Connection
Me.MousePointer = 11
cn.Open ConnectString()
With cn
.CommandTimeout = 0
.CursorLocation = adUseClient
End With
Set rs = New ADODB.Recordset 'Creates record set
strSQL = "SELECT * "
strSQL = strSQL & "FROM TABLE1 "
strSQL = strSQL & "WHERE FIELDNAME1 ='" & Me.Text1.Text & "' "
strSQL = strSQL & "ORDER BY FIELDNAME1;"
rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
If Not rs.EOF then
For b = 1 To rs.RecordCount
'<=== Do whatever you need to do with the recordset here
rs.MoveNext
Next b
Else
MsgBox "The recordset contained no Records"
End If
Beep
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
On Error GoTo 0
Exit Sub
Command1_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form " & Me.Name
End Sub
Private Function ConnectString()
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & <Type the Path and Name of DB Here> & _
";Jet OLEDB:Engine Type=5;"
End Function
Last edited by Mark Gambo; Nov 26th, 2006 at 08:35 PM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|