Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GoToControl command not working 1

Status
Not open for further replies.

Kiwiman

Technical User
May 6, 2005
88
GB
I have a quote form (frmQuoteHdr), where the user can create an invoice when the quote is accepted. When the quote is accepted, the cmdMakeInvoice button becomes visible. The On Click code executes (as below), except the final part, making the CustomerID the focus. I get the message "MS Access can't move the focus to the control CustomerID".

Any ideas would be appreciated as I am just finding my feet with Access and especially using VBA.

Regards

Private Sub cmdMakeInvoice_Click()

Dim strDocName As String, strDonName1 As String

strDocName = "qryDeleteTmp"
strDocName1 = "qryAppendTmp"

DoCmd.SetWarnings False

DoCmd.OpenQuery strDocName
DoCmd.OpenQuery strDocName1

If (Me.chkInstall = -1) Then
Call InstalmentInvoice
Else
Call NormalInvoice
End If
Forms!frmQuoteHdr!CustomerId.SetFocus


End Sub
 
If you have a control on the current form called "CustomerID", I would have thought

[tt]me!CustomerID.SetFocus[/tt]

should suffice. That is, unless the subs you're calling makes Access unable to set focus to the control.

Roy-Vidar
 
Thanks RoyVidar - I have tried your idea, but came up with the same results. I have had a look at one of the subs (see below) the initial code is calling, but do not see a problem, that would prevent the customerid from receiving the focus.

I have tried many methods, but to no avail. I appreciate any input.

Private Sub NormalInvoice()

Dim strPrompt As String, strStyle As String, strTitle As String
Dim strDocName As String
Dim varPress As Variant
Dim strFormat As String

On Error GoTo Err_NormalInvoice
strDocName = "qryInvoiceCreate"
strFormat = "##0.00%"

'Message Box to create a standard invoice - 100% charge
strPrompt = "Do you wish to create an Invoice based on the quote information?"
strStyle = vbYesNo
strTitle = "Create Invoice?"

varPress = MsgBox(strPrompt, strStyle, strTitle)

If (varPress = vbYes) Then
Me.cmdInvoiced = -1 ' flag the quote as invoiced, and prevent changes to the quote details
Me.txtInvPC = 1 ' set total invoiced to 100%
Me.txtTotal = Me.txtTotal + Me.txtInvPC
Me.Refresh
DoCmd.OpenQuery strDocName, acViewNormal

Else
Exit Sub
End If

Exit_NormalInvoice:
Exit Sub

Err_NormalInvoice:
MsgBox Err.Description
Resume Exit_NormalInvoice
End Sub
 
Is CustomerID on a subform or the mainform?

The syntax to goto the control will be slightly different, depending on where the control is located in relation to where the code is running from.
 
The control is on the main form, the subforms are linked by the QuoteID. Could it have something to do with the TAB Order?
 
does this work?

Code:
Private Sub cmdMakeInvoice_Click()

Me!CustomerId.SetFocus

Dim strDocName As String, strDocName1 As String

strDocName = "qryDeleteTmp"
strDocName1 = "qryAppendTmp"

DoCmd.SetWarnings False

DoCmd.OpenQuery strDocName
DoCmd.OpenQuery strDocName1

If (Me.chkInstall = -1) Then
    Call InstalmentInvoice
    Else
    Call NormalInvoice
End If


End Sub

HTH,
fly

[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]

Martin Serra Jr.
[blue]Shared Database_Systems and _Applications across all Business_Areas[/blue]
 
Thanks Fly

Worked like a dream - sweet as!!:)
 
to explain a little further:
I think, that the subs InstalmentInvoice or NormalInvoice you called in your cmdMakeInvoice_Click() might open a database object (a query) that gets the focus by being opened, and therefore Access could not move to the control on the form anymore, because focus of the form was lost.
That's why I suggested to move the focus to CustomerId first, and then run the rest.

Greetings,
fly

[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]

Martin Serra Jr.
[blue]Shared Database_Systems and _Applications across all Business_Areas[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top