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

Finding record in a sub form using FindRecord

P: 2
I am trying to use the FindRecord function in my 2003 database.
My code is
Expand|Select|Wrap|Line Numbers
  1. Dim Orderho As Integer
  2. Orderho = Me.cboFindByOrder
  3. Forms!test!Order!OrderID.SetFocus
  4. DoCmd.FindRecord Orderho, , True, , True
It does not work when I use the variable, but will work if I put a number figure such as 12 in teh function for example
Expand|Select|Wrap|Line Numbers
  1. DoCmd.FindRecord 12, , True, , True
Is the problem with declaration of the variable?
Any help would be appreciated thanks
Sep 14 '17 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 1,430
The declaration should be of the same type as the field being searched, so guessing that OrderID is an autonumber, Autonumbers are Long

Assuming that Forms!test!Order is a subform, to refer to a control on it (such as OrderID) use

Expand|Select|Wrap|Line Numbers
  1. Forms!test!Order.Form!OrderID
It's always worth putting a halt in your code, and checking whether Forms!test!.Form!Order is actually getting the focus

Sep 14 '17 #2

Expert Mod 15k+
P: 31,494
You say it does not work, yet you don't tell us what does happen. An error description is helpful for errors. If it simply doesn;t find the correct record, or move the record pointer at all, we also need to know that.
Sep 15 '17 #3

P: 2
Thank you for your replies,
I have changed the variable to Long and added the line of code
Forms!test!Order.Setfocus before
to make sure that OrderID has the focus
but it still does not work. There are no error messages either but now OrderID has the focus.
Sep 15 '17 #4

Expert Mod 15k+
P: 31,494
I assume then that what you mean but not working must be that it doesn't move from the current record. I'm afraid I can't see why. I would assume that there is something which is causing it to fail but which you haven't shared with us.

Generally I would expect code such as that to work.

I can state unequivocally that the focus was fine in the first instance as when you used the literal value 12 it did work. So, it seems clear there is something about the variable used. You could try using Val() around the reference to your variable. That should work, but it isn't the answer to your question. We can only help with that when we know what it is you aren't telling us.
Sep 15 '17 #5

Post your reply

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