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!

Dtpicker code doesnot prefrom as it should

Status
Not open for further replies.

Panchovia

Programmer
May 6, 2010
48
0
0
CW
Private Sub Command86_Click()

If Me.NewRecord Then
If Nz(Me.Aliasdate) > 0 And Me.aliasamount = Null Or Me.aliasamount = 0 Or Me.Aliasdate = Null Or Mycheckbox = False And DTPicker6.Value = Date Then
MsgBox ("No record will be added"), vbOKCancel
Beep
End If
Else
MsgBox ("Saving record"), vbOKCancel
Beep
DoCmd.RunCommand acSaveRecord
End If
End sub
This button should evalute the date picker values to save the record or not
if the user does enter the form by mistake and click on this button it should give him the message no record will be added and then exit ( the dtpicker checkbox is then unmark but you seee the current date in the dtpicker right now this does work when you click on the comman button)
if the user enter the form and activate only the dtpicker and does not fill in the other fields and opts for exit it should give the message no record will be added (this part works fine with the code)
when the user enters the form and click on the dtpicker and he fills all the field it should give him the message saving record and the exit the form to the main form,(this part doesn't work)
What do I miss in this code.

Panchovia
 
me.aliasamount = null
will never be true. It always returns null. Here is a test to prove it

x = null
?x = null
Null
x = 1
?x=null
Null

you can use
isNull(me.aliasamount)
For dates use
isDate(me.aliasdate) ' returns true only if it can be resolved as a valid date
to check for null, empty space, and spaces can be done with
if trim(me.someControl & " ") = "" then
 
Majp

Thank you very much
Here is the new code the first part works correctly but the parts that follows after the Else statements doesn't work I understand it because it has to save a record the first statement state if me.newrecord so the else is there isn't any record do I have to ommit the else or what

If Me.NewRecord Then
If Nz(Me.Aliasddate) > 0 And IsNull(Me.Aliasamount) Or Me.AliasAmount = 0 Or IsNull(Me.Aliasdate) Or Mycheckbox = False And DTPicker6.Value = Date Or IsNull(Me.DTPicker6.Value) Then
MsgBox ("No record will be added"), vbOKCancel
Beep
End If
Else
MsgBox ("Saving record"), vbOKCancel
Beep
DoCmd.RunCommand acSaveRecord
DoCmd.RunCommand acCmdClose
End If
End Sub

What is missing after the Else statement
 
what do you expect to happen, and what is happening?
 
Hi Majp

The endif before the else has move at the end before the end sub ,
Then everything works but after saving the record it give me an error( you cannot compact a database while running vb code I know that but I am not running any command to compact the database.)

What is causing this OOps
 
I am not sure what you are trying to close. If it is the current form then be specific

docmd.Close acForm, me.name

Check to make sure the thing that you think is closing does not have code in the onclose event.
 
Hi MajP
I am trying to close the pop form transactions and return the user to the main form

I have tried the code docmd.close acform, me.name allready it gives me a compile errorr in ms access 2010 editor

How is this possible
 
HiMajp

Here is the code so far everything works only
docmd.close Acform doesnot work
form name Frm_Transactions
any suggestions


On Error GoTo Error_Exit
If Me.NewRecord Then
If Nz(Me.Aliasdate) > 0 And IsNull(Me.Aliasamount) Or Me.Aliasamount = 0 Or IsNull(Me.Aliasdate) Or Mycheckbox = False And DTPicker6.Value = Date Or IsNull(Me.DTPicker6.Value) Then
MsgBox ("No record will be added"), vbOKCancel
Beep

Else
MsgBox ("Saving record"), vbOKCancel
Beep
DoCmd.RunCommand acSaveRecord
'Return to Main form
( docmd.Close acForm, me.name)

End If
End If

Exit_error_close:
Exit Sub


Error_Exit:
MsgBox Err.Description
Resume Exit_error_close
End Sub
 
copy the procedure and paste in text file. Then delete the procedure. Create a new procedure and paste it back in. Compile the code and see if you get an error.
 
Majp

I am convinced now that the dtpicker doesn't work as expected
even if it does it puts a blank record in the database
To clear this you have to run a delete query
 
To solve all your problems with the dtpicker remove the checkbox
in the properties set to no.

Pancho via
 
DoCmd.Close acForm, "Frm_Transactions"

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
Your logic may be flawed

Code:
If Nz(Me.Aliasdate) > 0 And IsNull(Me.Aliasamount)

if the Alisdate is > 0 and the Aliasamount has a value then the Else part of the statement will execute ignoring the fact that the dates are null because you use 'AND' both need to be true. To validate data in forms use the tag property of the control to indicate the controls to check using vba. this is a much cleaner way to check multiple controls on a form

eg.

Code:
Private Sub cmdSave_Click()
    On Error GoTo Err_CmdSave_Click
    Dim txtMessage As String

    For Each ctl In Me.Controls
        If ctl.Tag = "Needed" Then
            If Trim(ctl.Value & "") = "" Then
                'Highlight missing data fields
                Me(ctl.Name).BackColor = vbYellow
                blnError = True
            Else
                Me(ctl.Name).BackColor = vbWhite
            End If
        End If
    Next

    If blnError = True Then
        txtMessage = "All Required fields must be entered before the record can be added." & vbNewLine & _
                     "Enter a value or press 'Cancel' to abort the record."
        MsgBox txtMessage, vbOKCancel
    Else

Save Data code goes here

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
Hi Mazeworx I find your code interesting I will try it out and let you know, but I have allready solve the main problem by removing the checkbox from the Dtpicker


Thanks
Panchovia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top