By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,293 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,293 IT Pros & Developers. It's quick & easy.

Opening a form which goes directly to a particular record.

P: 9

Help would be highly appreciated!
I've got a form with clients which contains a subform with their orders in datasheet view. What I'd really like is to be able to open another form, which directly goes to the particular order details, for example by doublclicking the order id. I've know this is possible in forms view but is there any way of doing this while the subform is in datasheet view?

I've tried VBA and Macros but I just don't seem to be getting anywhere!

Thanks so much in advance!
Aug 7 '07 #1
Share this Question
Share on Google+
5 Replies

P: 47
A double-click event should work whether the form is in datasheet mode or not. I've tested this code when the form is in 'continuous forms' and 'datasheet' mode

  1. Sub txtID_Dbl_Click
  2. DoCmd.OpenForm "Account_details", acNormal, , "ClientID='" & txtID &"'"
  3. End Sub


BTW- I'm assuming ClientID is a string, otherwise you can leave out the single quotes
Aug 7 '07 #2

P: 9
Ok so I'm really new at this. This is what I have as an event procedure on my client ID Subform.

Private Sub ID_DblClick(Cancel As Integer)
Sub txtID_Dbl_Click()
DoCmd.OpenForm "NLFacturatie", acNormal, , "ID='" & txtID & "'"
End Sub
End Sub

As I'm guessing the first and last line of this code is what you meant with <Code> VB and <\Code> VB
(if I don't have those lines nothing happens at doubleclick.

However, now I keep getting the error message 'Expected End Sub'. I've opened 2 subs and closed them, so I really don't get my fault.
Aug 8 '07 #3

Expert 2.5K+
P: 3,532
You've posted the entire code sample given by Barry within your own sub, so that you have a sub within a sub, which is not allowed! When using code posted here, you have to remember a couple of things.

The names of fields, controls (textboxes, comboboxes, tables, etc) are frequently generic names. The members here usually don't know the exact name of your objects, and they frequently use boilerplate code that they have on hand to demonstrate how to solve a problem. You have to plug in the actual names of your own objects.

When someone posts an entire sub, such as

Private Sub ID_DblClick(Cancel As Integer)
'Code goes here
End Sub

you need to generate your own sub by way of your control's Properties Box, then copy and fill in the appropriate portion of the code (the bold line in the above code) not including the Private Sub... and the End Sub parts. Answers may involve placing code in Subs commonly used for multiple purposes. If, for instance, code is offered that needs to be placed in the Private Sub Form_Load() and you already have code in this sub, you must add the offered code to this sub in addition to the already existing code. You cannot simply add a second Sub Form_Load() sub.

This is the way your code should look:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ID_DblClick(Cancel As Integer)
  2.  DoCmd.OpenForm "NLFacturatie", acNormal, , "ID='" & ID & "'"
  3. End Sub
Now as to the matter of posting code here. I know the example given in Posting Guidelines for posting VB code is somewhat confusing. The problem is that if you actually show how the tags have to be done, the editor interprets that as actually being tags! Here's the drill:

Hi-lite the code in your post
At the top of the editor, Click on the # icon .

This will place

[ Code ] and [ /Code ]

tags around the code. For VB code you then have to go in and alter the first tag so that it looks like this

[ Code=vb ]

Note that Code=vb has to be just like that, no spaces between the letters and the equal sign. Also note that the tags are shown above with spaces between the square brackets and the tag content. When actually posting code there will be no spaces. To make sure you've got it right, try placing tags on your code, then click on Preview Post at the bottom of the editor. Your code should appear like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ID_DblClick(Cancel As Integer)
  2. 'Code goes here
  3. End Sub
Good Luck and Welcome to TheScripts!

Linq ;0)>
Aug 8 '07 #4

P: 9
thanx for the explanation cos I really wasn't sure about all that sub stuff. but i'm enjoying the challenge I must say!

Thanx for all the help!!!
Aug 8 '07 #5

Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Aug 8 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.