cmd buttons issue

LaRockera02

Registered User.
Local time
Yesterday, 19:19
Joined
Oct 21, 2011
Messages
83
I have two button on a form. One called "New Call" and the other "Save"

The Save button checks for all required fields and makes sure that the user enters all required info. My problem is that they can circumvent that by just clicking on the "New Call" button. Is there a way I can somehow disable the "New Call" button?

The "New Call" button's function is to append a record.

please help,

thanks
 
The simple answer would be to remove the button! However I suspect you need it for something, so the real question is when do you want it enabled and when you want it disabled? And what is the criteria that dictates the difference?
 
I would like to remove the "Save" button. My initial idea was to somehow make the "New Call" button check and make sure there's info there for all the required fields including the subform fields in order to move on to a new record.

I tried adding the code I have for the save button onto it but it doesn't work.

If there's a way to make that into just one button please let me know. I want the "New Call" button to check all required fields on both form and subform and then append a record.

thanks,
 
Hi, In your intial post you said you had a form then in your last one you mentioned a subform too. Could you give some more detail?

If you just want to append a record to one or more tables but first make sure that a bunch of fields have been filled out, you only need one button to do that.
 
HI,


You are correct I only want one button (New Call button) But I need it two do those 2 things I mentioned before.
1. Check all requred fields (in the subform and mainform)
2. append a record

The subform is in a datasheet format, not sure if that's neccessary. I'm only concerned with one data field inthe subform.

I named the main form CDatabase
the subform: CNote
subfrom data field: Note

let me know what else you need.

thanks,
 
Lets start with the controls on your main form.
What are their names, types and which are required

e.g. mytext1 > textbox > required
mycombo1 > combobox > required
mytext2 > textbox > not required

etc

First i'll show you how i check for required fields

Are you sure you want to check for required fields in the subform. If I understand correctly, the subform is of type datasheet and so just displays data from a query or table
 
Main form: CDatabse
Rep Name > combobox > required
Caller's Name > textbox > required
reason > comobox > required
Account# > textbox > not required
Date > is automatically inputed

Subform: CNote
Date> automatic
Note > required
I want to make it mandatory for the user to input data in the subform. If they don't I want the "New Call" button to stop them from proceeding. CNote displays data from a table.

thanks,
 
Is the user going to
(1) enter data into the subform by typing into it

or

(2) enter data in the controls on the main form which will show up in the subform once the button is clicked?
 
Could you attach your mdb file and post it? Or is the info confidential?
 
It is confidential sorry. Maybe I can include a txt file with the code. let me know if that would be ok
 
I have two button on a form. One called "New Call" and the other "Save"

The Save button checks for all required fields and makes sure that the user enters all required info. My problem is that they can circumvent that by just clicking on the "New Call" button. Is there a way I can somehow disable the "New Call" button?

The "New Call" button's function is to append a record.

please help,

thanks
1. Move the validation code from the Save button into a Function that will return True if all required fields have been completed or False if some are missing.
2. Call this function in your Save button and test the value returned, then proceed accordingly.
3. Call this function in your New Call button and test the value returned, then proceed accordingly.
 
Yes, by changing the Caption property of the button. E.g.:
Code:
If Me.[COLOR=Red]textbox[/COLOR].Caption = "Save" Then
    Me.[COLOR=Red]textbox[/COLOR].Caption = "New Call"
    ....[B] Validation [/B]and [B]Save[/B] code
Else
    Me.[COLOR=Red]textbox[/COLOR].Caption = "Save"
    .... [B]Validation[/B] and [B]New Call[/B] code
End If
In the On Dirty event of the form:
Code:
If Me.Dirty = True Then
    Me.[COLOR=Red]textbox[/COLOR].Caption = "Save"
Else
    Me.[COLOR=Red]textbox[/COLOR].Caption = "New Call"
End If
You may need to tweak it but that's the idea.
 
Hey I'm kind of a novice when it comes to this. But I'm not sure where I'm suppose to put the first part of the code. I got the on Dirty code in already.
 
In the On Click event of the button.

Also, make sure that the initial Caption is New Call.
 
this is what I have coded on On Click for the New Call button and I don't see any change

Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click

DoCmd.GoToRecord , , acNewRec
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click

If Me.cmdSave.Caption = "Save" Then
Me.Add_Record.Caption = "New Call"
'.... Validation and Save code
Else
Me.cmdSave.Caption = "Save"
'Validation and New Call code'
End If

End Sub



and what I got On Dirty

Private Sub Form_Dirty(Cancel As Integer)
If Me.Dirty = True Then
Me.cmdSave.Caption = "Save"
Else
Me.Add_Record.Caption = "New Call"
End If
End Sub
 
Please be a bit more descriptive. Nothing happens when you do what??
 
There's no change on what I had before. If I hit the New Call button it would countinue to a new record even if there's no data inputed in the required fieds. I wanted the New Call button to check for required fields on both form and subform. If no data is inputed then I would like for it to prevent the user from proceeding until they enter data for all the required fields. I hope that clarified things.

thanks,
 
You said you have some validation code and in my first post I explained (or showed you) how you can incorporate that code into what I gave. I don't see any validation code in your post and you put the code in the wrong place.

I have re-written it to make it clearer:
Code:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click

    If Me.cmdSave.Caption = "Save" Then
        Me.Add_Record.Caption = "New Call"
        ' ... Validation code GOES HERE ...
        If [COLOR=Red]ValidationIsFine[/COLOR] Then
            ' ... Save code here GOES HERE ...
        End If
    Else
        Me.cmdSave.Caption = "Save"
        ' ... Validation code GOES HERE ...
        If [COLOR=Red]ValidationIsFine [/COLOR]Then
            DoCmd.GoToRecord , , acNewRec
        End If
    End If
    
Exit_Add_Record_Click:
    Exit Sub
    
Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click

End Sub
Those comments mean something. ValidationIsFine is the function that performs the validation on required fields (as explained in my first post).
 

Users who are viewing this thread

Back
Top Bottom