Two clicks instead of one to make command button work....Why?

BarryMK

4 strings are enough
Local time
Today, 02:30
Joined
Oct 15, 2002
Messages
1,349
Hello again, I hope :rolleyes: this is the last tiny wrinkle to smooth out of this database!

This code is placed in the LostFocus event of the only text field on the last of four stLinkCriteria linked popup forms, in order to refresh the data in the underlying table before previewing a report showing the current record.

After filling in the receipt number in Text Field "TextReceiptNo" the user then selects a Command Button which runs a macro to preview the report. (I'd rather use code here but the macro seems to work better so I'm sticking with it).

Everything works ok except it takes two clicks of the Command Button to preview the report. How can I get this down to one click please?

Code:
Private Sub TextReceiptNo_LostFocus()

Dim rs As String
rs = Forms!RecDetsAC!StrayRef

DoCmd.RunCommand acCmdSaveRecord
Forms!RecDetsAC.Requery
Forms!RecDetsAC!StrayRef.SetFocus
DoCmd.FindRecord rs


End Sub


Cheers Barry
 
I suspect that the form that holds the command button does not have the focus, so the first click selects the form and the second activates the command button.
 
neileg said:
I suspect that the form that holds the command button does not have the focus, so the first click selects the form and the second activates the command button.

Thanks to both responses, firstly to upload the db will take a bit of time and I'm off site this pm so I may take you up on your kind offer tomorrow. I suspect it is a focus problem, if so any ideas how to sort??
 
Rich said:
Why are you Requerying the form?

Hi Rich

How about - "I'm not really sure!"

What I need is to ensure that once the text field has had data input, the report which is selected as the next step will contain that data. Presumably I should be requerying the table not the form but I've had problems with the various bits of code I've tried using to do that. Any ideas would be appreciated, in the meantime I'll have a play with it again.

Cheers
 
Just
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport, etc etc
on your command button should be enough,
I only ever use Refresh, Find rs etc if I want to say Re-order newly added entries to a subform or re-calculate a running sum on a form. I don't think you need to Refresh in this case.
 
Rich. I'll give it a go and let you know how I get on thanks.
 
Many tThanks Rich, I wasn't seeing the wood for the trees. Simplicity rules. To clarify for anyone following this thread - here is the code that works:

Private Sub Command19_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunMacro "PrintAC"
End Sub
 

Users who are viewing this thread

Back
Top Bottom