Results 1 to 5 of 5
  1. #1
    tia is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    12

    How to open a specific table by clicking the image in the form

    I have two tables named: Contacts and Image.



    I'd like to know what to do so that when I click the picture in the FORM VIEW it will open the table named Image in a DATASHEET VIEW.

    and when I am in the DATASHEET VIEW of the table named Image and click the ID number of a certain contact it will open the Form in Form View containing the specific fields about that contact.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi tia,

    This code in the Click event of your Image should do the trick for you as far as opening your table in datasheet view.

    On my Form I put an image called Image7.
    I Right-Clicked the Image
    Opened the Properties
    Went to the Events Tab
    Selected the [...] to the right of 'On Click'
    and then typed:
    DoCmd.OpenTable "Image"
    in there.

    This is what it looks like in my Visual Basic window.


    Code:
     
    Private Sub Image7_Click()
    DoCmd.OpenTable "Image" 
    End Sub
    As far as clicking IN THE TABLE . . . to open a Form - I have never done that and don't think that is possible.

    I think what you should try instead is to create a Form based on your Table and open the Form when your Image is clicked.

    Then - when you open the Form connected to your Table - and navigate to a record on that form - you can have a cmd button that takes you to the detail for the record you selected.


    I hope this helps!
    Last edited by Robeen; 10-04-2011 at 01:36 PM. Reason: Omission.

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    As far as Clicking in the Form that displays your Table in Datasheet View:

    In the On Click Event of the ID field on the Form, put in this:

    Code:
     
    Private Sub ID_Click()
    DoCmd.OpenForm "FormName", , , "ID = " & Me.ID
    End Sub
    For the above code - you need to make sure that:
    1. The Form you try to open has a field named ID and
    2. The Form you are IN has a field on it named ID.
    3. In place of "FormName" - put in the Name of the Form you want to open.

    I hope this helps!

    Let me know if you need more help!
    Last edited by Robeen; 10-04-2011 at 01:36 PM. Reason: Typo.

  4. #4
    tia is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    12
    Thank you for your reply, I followed it but nothing happened.

    I tried to follow this guide which appears after typing Docmd:
    OpenTable(TableName,[View As AcView = acViewNormal],[DataMode As AcOpenDataMode = acEdit])

    But after hitting enter an error message will appear.
    I want to open the table in its normal view and for read only.
    What should I do? Thank You

  5. #5
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Arrow Try this out

    I would suggest you use two forms instead of using a form and table. I believe you cannot 'click' in a row of a table. So what you can do is, use a second form, that would display all the data of your table, exactly as it is in the table. Heres how you do it:

    If you have a form, say "formMain" which has the image, in the button_click event of the image, put the following code


    DoCmd.OpenForm "form1", acFormDS


    (the above code will make the form1 display the table's data)


    Now you need to create form1 for it to be displayed. open a new form in design mode, set the record source for the form to your table (if you use "table1", select table1 in the dropdown for the Record Source under the 'Data' tab in the form properties). And then change the Default View under the 'format' tab to "Continuous Forms".


    Now if you have 4 fields in your 'table1', put 4 textboxes on the form1 (Put them anywhere, design doesnt really matter). Select each textbox, go to the Properties Sheet - Data tab - Control Source and select the respective fields from the dropdown list. That being done, save it as "form1" (or whatever name you want to give).


    After this, when you open 'formMain' in formview and click the image, it should open the 'form1' in a tabular view.


    Now for the second part.


    Open 'form1' in form view. Click on any row of the 'ID Field' and go to the 'On Dbl Click' event procedure under the 'Event' tab in the property sheet. Then put the following code in there:

    Dim stDocName As String
    Dim s As String
    s = "ID_field = " & Me.ID_field

    stDocName = "form2"

    DoCmd.OpenForm stDocName, , , s, , acDialog, Me.ID_field

    (acDialog is optional, it would just make your form2 a pop up modal)

    That will open 'form2' (remember that you have not created this yet). You need to set the record source again for form2, based on what data (either from another table or query) it should display. Make sure you have an unbound textbox on form2 and code it to match with ID_field from 'form1'

    Hope that helps!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2013, 10:12 AM
  2. Open Form to Specific Record
    By batowl in forum Forms
    Replies: 1
    Last Post: 04-08-2011, 10:10 AM
  3. Replies: 1
    Last Post: 04-11-2010, 04:05 AM
  4. Replies: 7
    Last Post: 11-29-2009, 01:44 PM
  5. Open to specific form
    By ecpike in forum Forms
    Replies: 2
    Last Post: 06-12-2009, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums