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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-Time error 2046 with 3rd instance of 'GoToControl'

Status
Not open for further replies.

stevo99

Technical User
Mar 16, 2007
8
0
0
US
Access 2007. Disclaimer: I'm new at this.

I have frmCVBook based on tblCVBook both of which have 6 fields; 4 are visible in the form and 3 require user input for use later in a macro. There are no records yet. The dimmed variables strLOC, intREPS, and strREMARKS are assigned values via InputBox and used to fill fields in table record. The problem is that regardless of the order in which they are stated in the form code, the 3rd instance of the DoCmd.GoToControl, always generates the same error, that is: "RunTime Error '2046': The command or action 'GoToControl' isn't available now." I would appreciate anyone's help. Thanks! (similar to thread702-1455510?)

Here's entire Form code:

Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)

'Dim variables
Dim strLOC As String
Dim intREPS As Integer
Dim strREMARKS As String

'Collect data
DoCmd.GoToControl "LOC"
strLOC = InputBox("Trial Code(LL)?")
LOC = strLOC

DoCmd.GoToControl "REPS"
intREPS = InputBox("How many reps?")
REPS = intREPS

DoCmd.GoToControl "REMARKS"
strREMARKS = InputBox("Remarks?")
REMARKS = strREMARKS

DoCmd.Close (acForm)
End Sub
 
Thanks for your response Duane. I thought I needed them to set focus on the correct field in underlying table; apparently not. It worked wo those 3 statements. I made a couple of other changes because I was re-writing the same record. So it now seems to run okay as the following:

DoCmd.openForm "frmCVBook"
DoCmd.GoToRecord acDataForm, "frmCVBook", acNewRec

'Dim variables
Dim strLOC As String
Dim intREPS As Integer
Dim strREMARKS As String

'Collect data
strLOC = InputBox("Trial Code(LL)?")
LOC = strLOC

intREPS = InputBox("How many reps?")
REPS = intREPS

strREMARKS = InputBox("Remarks?")
REMARKS = strREMARKS

DoCmd.Close acForm, "frmCVBook", Save:=acSaveYes

End Sub

Now I guess I have to learn how to access the values when the subsequent macro runs.

Thanks again for your remarks.--Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top