Link to home
Create AccountLog in
Avatar of 25112
25112

asked on

you can’t reference a property or method for a control unless the control has the focus- error

after a button click on the screen, click on any of the tabs give the above error..

is there a simple way to reset after the button click?
Avatar of 25112
25112

ASKER

this is the button click code

Private Sub DuplicateRecBtn_Click()
  On Error GoTo Split_Err
  Dim OldRecNum As Integer

  Dim db As Database
  Dim ds As Recordset
  Dim NewFrmID As Long
 
  Set db = CurrentDb()
  Set ds = db.OpenRecordset("Field_Report", dbOpenDynaset)
  OldRecNum = RecordNumTextBox.Value
  With ds
    .AddNew                 'Add New Record
    !DB_Year = Me("DB_Year")
    !Grower_Idx = Me("Grower_Idx")
    !MapFile = Me("MapFile")
    !Last_Crop = Me("Last_Crop")
    !Lab_Num = Me("Lab_Num")
    !Report_Date = Me("Report_Date")
    !Field_Num = Me("Field_Num")
    !Total_Acres = Me("Total_Acres")
    !Lime_Cal_Found = Me("Lime_Cal_Found")
    !Lime_Cal_Tons = Me("Lime_Cal_Tons")
    !Lime_Mag_Found = Me("Lime_Mag_Found")
    !Lime_Mag_Tons = Me("Lime_Mag_Tons")
    !CEC = Me("CEC")
    !Soil_Ph = Me("Soil_Ph")
    !Buffer_Ph = Me("Buffer_Ph")
    !P205_Actual_ppm = Me("P205_Actual_ppm")
    !P205_Results = Me("P205_Results")
    !Nitrogen_Residual = Me("Nitrogen_Residual")
    !K20_Results = Me("K20_Results")
    !K20_Actual_ppm = Me("K20_Actual_ppm")
    !RootWorm_Level = Me("Rootworm_Level")
    !Weed_Level = Me("Weed_Level")
    !OM_Rate = Me("OM_Rate")
    NewFrmID = !Fld_Idx
    .Update
    'NewFrmID = !Fld_Idx
  End With
  ds.Close
  MsgBox ("Split Selected Record")
  Me.Insecticide.SetFocus
 
 
  If Val(Forms![Field Data Entry].Grower.Value) > 0 Then
    Call SetLastIndex(Val(Forms![Field Data Entry].Grower.Value))
  End If
  Me.Requery
 
  Me.RecordsetClone.FindFirst "[Fld_Idx] = " & NewFrmID
  Me.Bookmark = Me.RecordsetClone.Bookmark

 
  Exit Sub
 
Split_Err:
  MsgBox Error$
  Resume SplitOut
  Resume Next
 
SplitOut:
  Exit Sub
   
End Sub
Avatar of 25112

ASKER

http://www.dbforums.com/microsoft-access/973776-you-cant-reference-property-method-control-unless-control-has-fo.html

suggests a setfocus.. where would you put one in the above code, if that is the solution?
SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of 25112

ASKER

i turned off the error handling.. but could not get any other message..

pl see attached..

when the red circled button is clicked, the blue colored tab gives the error..

if the button is not clicked, then the tabs don't give any error..  any clues from that?
misc.png
Avatar of 25112

ASKER

fyed, i could not find SetLastIndex in the code.. can you suggest how can i look for it?
Avatar of 25112

ASKER

hnasr, thanks- i tried that for all those enties.. but that did not do it either
Avatar of 25112

ASKER

helen, do you mean this:
 !Buffer_Ph = Me("Buffer_Ph")

does not the '!' differentiate this?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of 25112

ASKER

thank you: here is the code:

Public Sub SetLastIndex(OurIndex As Long)
  Dim db As Database
  Dim ds As Recordset
  Set db = CurrentDb()
  Set ds = db.OpenRecordset("Select * FROM [Options]" & ";", dbOpenDynaset)
  ds.MoveFirst
  ds.Edit
  If OurIndex <> 0 Then
    ds("WorkingIndex") = OurIndex
    CurrentGrower = OurIndex
  End If
  ds.Update
  ds.Close
End Sub
Avatar of 25112

ASKER

thanks for your explanation on control source..

so you would suggest

!DB_Year = Me("DB_Year")
to
!txt_DB_Year = Me("DB_Year")
?

then this will affect whereever !DB_Year is used in the same app? (will do a replace all search feature?)
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of 25112

ASKER

thanks a lot...

1)If I change control name on form, what are any consequence to think about? so that is the best guess, right now, right? (for the problem we encounter)...

2)how do i know/check if i have unbound form?

3)is SetLastIndex all clear?

4)is 'clear' an issue (as against usage of setfocus as one of the posts above)
You can use my LNC Rename add-in to semi-automatically rename objects and controls according to the LNC.  There are several versions, depending on your Access version.  See the Code Samples page of my Website to select and download the appropriate one.

http://www.helenfeddema.com/CodeSamples.htm