Re: Disable Command Button After Click

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I moved the 'Me.AddQsts.Enable = FALSE' to the 'on enter' property for the
AddQsts field and that works; the button is greyed out and unavailable. I
can add the score to the first record but only after I use my cursor to move
down to the second record and back up to the first record. Can you please
tell me how to fix this?

Many thanks!


"ridgerunner" wrote:

Is this going to cause a problem?
IF YOU HAD A DIRTY NEW RECORD THEN IT IS NO LONGER A NEW RECORD BECAUSE OF
THE CODE ABOVE.

The code below:
Me.OtherControlName.SetFocus '-- Use YOUR OtherControlName of course.
Me.AddQsts.Enable = FALSE

is causing an error message "Run-time error '2164' " " You can't disable a
control while it has the focus."

I set the focus to my other control name and the cursor "lands" there but I
cannot add the score.

Thanks.
"ruralguy via AccessMonster.com" wrote:

Notes in line:

ridgerunner wrote:
Thanks so much for your help. Here is the code.

Private Sub AddQsts_Click()
'save record if changes have been made
If Me.Dirty Then Me.Dirty = False


IF YOU HAD A DIRTY NEW RECORD THEN IT IS NO LONGER A NEW RECORD BECAUSE OF
THE CODE ABOVE.

'if we are on a new record, give user a message
If Me.NewRecord Then
MsgBox "You must complete the store and date" _
, , "Cannot create questions"
Exit Sub
End If

If IsNull(Me.InspID) Then
MsgBox "You must fill out the store and date" _
, , "Cannot create questions"
Me.InspID.SetFocus
Exit Sub
End If

Dim strSQL As String

strSQL = "INSERT INTO tblDMInspecDet (InspID, DMCatID, QstID) " _
& " SELECT " & Me.InspID _
& ", DMCatID " _
& ", QstID " _
& " FROM tblQuestions;"

CurrentDb().Execute strSQL

THE ABOVE LINE SHOULD BE:
CurrentDB.Execute strSQL, dbFailOnError

AND YOU SHOULD HAVE ERROR HANDLING CODE IN THIS FUNCTION.


'make the new records show up on the subform
Me.subfrmDMInspDet.Requery


ADD THE FOLLOWING:

Me.OtherControlName.SetFocus '-- Use YOUR OtherControlName of course.
Me.AddQsts.Enable = FALSE

End Sub

Yes. Can you post the code you have in the click event of the CommandButton
please.
[quoted text clipped - 7 lines]
user can keep adding the same records. Can someone please tell me how to do
that?

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200805/1


.



Relevant Pages

  • Re: Disable Command Button After Click
    ... MsgBox "You must complete the store and date" _ ... Dim strSQL As String ... AND YOU SHOULD HAVE ERROR HANDLING CODE IN THIS FUNCTION. ...
    (microsoft.public.access.forms)
  • Re: Disable Command Button After Click
    ... IF YOU HAD A DIRTY NEW RECORD THEN IT IS NO LONGER A NEW RECORD BECAUSE OF ... MsgBox "You must complete the store and date" _ ... Dim strSQL As String ...
    (microsoft.public.access.forms)
  • Navigation AddNew Record woes
    ... 'Called by: Navigation buttons on forms ... Set rsNavigate = frmCurrent.RecordsetClone ... MsgBox "You are on the first record", vbOKOnly, "Data ...
    (comp.databases.ms-access)
  • Re: Showing problem
    ... better to use char array for phonenumber field too.... ... lets say user input something like: ... then it will overflow and store wrong information. ... you have valid data only in first record, ...
    (comp.lang.c)
  • RE: Sub Report Problem
    ... I have just determined that using a subform won't work either. ... subform will show the first record but I can't see any additional records. ... > Store Call - Actions ... The individual subreport contains the information but ...
    (microsoft.public.access.reports)