Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

How to make a Add key disabled after adding one record unless

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 05 Jul 2007 22:40 GMT
Hi,
I have a form where I am adding records. There are two boxes where one has
to put the lineitemnumber and another box where one has to put the
description. Unless the above two boxes are filled in the Add command box
need to be disabled. Now, the problem is after adding one record the Add
button is enabled and I cannot disable it. I would appreciate any help to
solve this.
The error message is:
The methos is not supported
The following is the code:
Private Sub cmdadd_Click()

On Error GoTo Err_cmdadd_Click
   If (IsNull(Me.LineItemID) = True) Or (IsNull(Me.Description) = True) Then
     MsgBox ("You cannot save null values to the system")
   End If
   Dim db As Database
   Dim rstApp As Recordset

   Dim strSQL As String
   Dim strLineItemID As String

   Set db = CurrentDb
   Set rstApp = db.OpenRecordset("tblLineItems", dbOpenDynaset)
   strLineItemID = Trim(Me.LineItemID)
   
   If MsgBox("OK to Add " & strLineItemID & " ?", vbYesNo, "Confirm Add") =
vbYes Then
       With rstApp
           .AddNew
           !LineItemID = Me.LineItemID
           !Description = Me.Description
         strSQL = "SELECT [tblLineItems].[LineItemID],
[tblLineItems].[Description] FROM tblLineItems order by tblLineItems"
           
           .Update
           MsgBox ("Records added to system")
       End With
       
   Else
       MsgBox "Add Cancelled"
   End If
   Forms![frmAddLineItems]![LineItemID] = ""
   Forms![frmAddLineItems]![Description] = ""
   Me!LineItemID.SetFocus = True
   Me!cmdadd.Enabled = False
   Exit Sub
Exit_cmdadd_Click:
   Exit Sub
Err_cmdadd_Click:
   MsgBox Err.Description
   Resume Exit_cmdadd_Click
   
End Sub
Carl Rapson - 06 Jul 2007 16:19 GMT
> Hi,
> I have a form where I am adding records. There are two boxes where one has
[quoted text clipped - 52 lines]
>
> End Sub

The easiest way for me has been to check for values in both fields in each
field's AfterUpdate event, and if both are non-Null enable the button. The
error you're getting is probably caused by the fact that you can't disable a
command button while it has focus, and the button has focus because you're
in the button's Click event. Just shift focus to some other control, and
then you can disable the button.

Carl Rapson
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.