Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 13th, 2006, 04:11 AM
Registered User
 
Join Date: Oct 2006
Location: Bangalore, Calicut, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to roshla_p
Default MS Data Grid control in ms access application

hi

first time i am into ms access application.in taht i need to add data's to ms datagrid manually.can anyone explain me how to do taht .i did the smae in visual basic by setting datasource and data memeber property of the datagrid .but here i dont know how to refer the tables in the same database.when i am trying to connect it by setting teh provider name and path,it is showing error database is currently locked .it si very urgent.can anyone help me !!!!
Reply With Quote
  #2 (permalink)  
Old October 13th, 2006, 02:26 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Two things:

If you write this code and then immediately try to execute it, you may get an error that the database is put in a state by current user and can't do what you want. If that happens, save your code and then reopen the database and try your code again, but not from VBA, from the control or event you are coding.

Are you using ADO or DAO? Where is your data? Is it in the current mdb file, or in a remote file or DBMS?



mmcdonal
Reply With Quote
  #3 (permalink)  
Old October 14th, 2006, 07:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

To refer to tables in the same database use CurrentProject.Connection. The following will set an ADO recordset as the data source of a Microsoft DataGrid Control 6.0 (SP6):

Code:
Private Sub Form_Load()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String

    Set cnn = CurrentProject.Connection
    strSQL = "SELECT * FROM tblRecords"

    Set rst = New ADODB.Recordset

    rst.CursorLocation = adUseClient
    rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic

    Set grdDataGrid.DataSource = rst

End Sub
Oddly, the cursor type, cursor location, and lock type configuration I'm using appears to be absolutely the ONLY recordset configuration that gives the grid control a bookmarkable recordset that it can use as a datasource.

Anyway, good luck using ActiveX controls with Access/VBA. You're a braver man than me. Hope you have a copy of the VB6 help files around. I've gotten a bunch of ListView and TreeView controls fairly functional, but never did much with the DataGrid. Just don't have that much hair left to pull out.

HTH,

Bob



Reply With Quote
  #4 (permalink)  
Old October 15th, 2006, 10:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

After some further tinkering with the cursor issue, what appears needed is a client-side cursor (which is always static).

Reply With Quote
  #5 (permalink)  
Old October 16th, 2006, 02:30 AM
Registered User
 
Join Date: Oct 2006
Location: Bangalore, Calicut, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to roshla_p
Default

hi Mr.mmcdonal and Mr.Bob Bedell ,

Thanks for your reply .but still it has problem.i am not able to enter data's to it .i mean it is not takking any value .i can point thh cursor in to each columns but what i am trying to enter it is not taking up.
i am using ADo connection for this

    Set cnn = CurrentProject.Connection
    strSQL = "select DimId,DimensionDesc,Dimension,Tolerance,DrawingShe et,DrawingZone from PartDetails"
    rst.CursorLocation = adUseClient
    rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
    Set dgdDetails.DataSource = rst
    dgdDetails.Refresh

Reply With Quote
  #6 (permalink)  
Old October 16th, 2006, 02:37 AM
Registered User
 
Join Date: Oct 2006
Location: Bangalore, Calicut, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to roshla_p
Default


hi Mr.mmcdonal and Mr.Bob Bedell ,

Thanks for your reply .but still it has problem.i am not able to enter data's to it .i mean it is not takking any value .i can point the cursor in to each columns but what i am trying to enter it is not taking up.
i am using ADo connection for this

    Set cnn = CurrentProject.Connection
    strSQL = "select DimId,DimensionDesc,Dimension,Tolerance,DrawingShe et,DrawingZone from PartDetails"
    rst.CursorLocation = adUseClient
    rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic
    Set dgdDetails.DataSource = rst
    dgdDetails.Refresh
Will u be able to help me again :-)

Thanks,
Roshla


Quote:
quote:Originally posted by Bob Bedell
 To refer to tables in the same database use CurrentProject.Connection. The following will set an ADO recordset as the data source of a Microsoft DataGrid Control 6.0 (SP6):

Code:
Private Sub Form_Load()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String

    Set cnn = CurrentProject.Connection
    strSQL = "SELECT * FROM tblRecords"

    Set rst = New ADODB.Recordset

    rst.CursorLocation = adUseClient
    rst.Open strSQL, cnn, adOpenStatic, adLockBatchOptimistic

    Set grdDataGrid.DataSource = rst

End Sub
Oddly, the cursor type, cursor location, and lock type configuration I'm using appears to be absolutely the ONLY recordset configuration that gives the grid control a bookmarkable recordset that it can use as a datasource.

Anyway, good luck using ActiveX controls with Access/VBA. You're a braver man than me. Hope you have a copy of the VB6 help files around. I've gotten a bunch of ListView and TreeView controls fairly functional, but never did much with the DataGrid. Just don't have that much hair left to pull out.

HTH,

Bob



Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
a Grid control in MS Access? sbmvr Access VBA 3 April 3rd, 2014 10:59 AM
how to merge cells in MS Flex Grid control manishdev Beginning VB 6 0 June 6th, 2007 09:03 AM
Other application in MS Access anukagni Access 3 May 10th, 2006 12:55 AM
MS Access Application Startup arnniema Access 6 September 2nd, 2005 10:39 AM
Exporting data from MS Excel sheet to Ms Access ajindal General .NET 1 January 17th, 2005 02:00 AM



All times are GMT -4. The time now is 03:39 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.