Save-Button routine

csdrex87

Registered User.
Local time
Today, 13:49
Joined
Jul 1, 2009
Messages
66
Ok so this is a rather simple question. Im somewhat new to VB but Im creating a button to check if something is in the table with a Dlookup but I dont know what the command is for save.

My code looks like this

If
=Dlookup("Emp_ID","tblEmployeeDaily","Emp_ID=" &
Emp_ID AND "DailyDate=" & DailyDate)

[Insert Command for save all data fields to table]

Else

[Insert Command to cancel and go back to form]

End If


I've gone to countless websites searching for a list of VBA code like they have for C programming code but to no avail. :-(
Can someone help me with these 2 lines of code or perhaps help me with a link to a website with all of the basic commands from VBA coding?
 
Are you not using a bound form? If you use a bound form it will save when you move to the next record or close the form. You can stop the save if it doesn't validate by using the form's Before Update event. I would do it that way, if at all possible.
 
Ah i suppose it is a bound form. So if I used a beforeUpdate event how would i keep it from saving the data? Maybe msgbox?
 
Ah i suppose it is a bound form. So if I used a beforeUpdate event how would i keep it from saving the data? Maybe msgbox?

You can use your DLookup to see if something exists:
Code:
Private Sub Form_BeforeUpdate()
 
If Nz(Dlookup("Emp_ID","tblEmployeeDaily","Emp_ID=" & Emp_ID AND "DailyDate=" & DailyDate), "") <> "" Then
   Cancel = True
   If MsgBox("This already exists, do you want to abandon this record?.", vbExclamation, "Error") = vbYes Then
         Me.Undo
   End If
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom