A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Record validation before save



 
 
Thread Tools Display Modes
  #1  
Old May 6th, 2009, 06:49 AM posted to microsoft.public.access
kMan
external usenet poster
 
Posts: 36
Default Record validation before save

Hi,
I am trying to validate that a record doesn't exist in a table before saving
using a dlookup function, however I keep getting a "type mismatch" on
runtime. Can anyone help, here is the code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant

varResult = DLookup("TimeOn", "TimeOn", "EmployeeID = " &
Forms!ClockOn!EmployeeID _
& " AND DateIn =#" & Forms!ClockOn!DateIn & "#")

If IsNull(varResult) Then
MsgBox "Your Time On record has been successfully recorded", vbOK
'Cancel = True
'Me.Undo
End If

End Sub

Any assistance greatly appreciated.
  #2  
Old May 6th, 2009, 07:42 AM posted to microsoft.public.access
tina
external usenet poster
 
Posts: 1,997
Default Record validation before save

well, nothing jumped up and bit me on the nose. so you need to troubleshoot.
first, put a break in the code to see what line is generating the error.
then start checking that line - values assigned to variables, values in
referenced controls. and doublecheck the data types of referenced fields in
tables. you're looking for mismatched data types: a number compared to a
string, a string compared to a date, etc.

hth


"Kman" wrote in message
...
Hi,
I am trying to validate that a record doesn't exist in a table before

saving
using a dlookup function, however I keep getting a "type mismatch" on
runtime. Can anyone help, here is the code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant

varResult = DLookup("TimeOn", "TimeOn", "EmployeeID = " &
Forms!ClockOn!EmployeeID _
& " AND DateIn =#" & Forms!ClockOn!DateIn & "#")

If IsNull(varResult) Then
MsgBox "Your Time On record has been successfully recorded", vbOK
'Cancel = True
'Me.Undo
End If

End Sub

Any assistance greatly appreciated.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.