Validation two condition (1 Viewer)

n3wguys

Registered User.
Local time
Today, 08:36
Joined
May 14, 2012
Messages
39
Dear All,

I have one case about validation in the form

example: I have entry in table this mention below:

No.Register | Code_machine
________________________

001 | X01
002 | X01
001 | X02
003 | X02
003 | X01
002 | X03


How to make validation for this case when I will submit the data 001 and X01, the system will be cancel and show warning message : "Data Duplicate!".
and of course with this happen, the user will be know what they will submit, it have been submit into table before by other user.


if I will do make with one validation like noregister as checking data and use the DLookup, this is no problem.

please help me.

thanks before and GBU
 

Attachments

  • myexample.accdb
    508 KB · Views: 78
Last edited:

JHB

Have been here a while
Local time
Today, 17:36
Joined
Jun 17, 2012
Messages
7,732
Try the attached database.
 

Attachments

  • myexample.accdb
    400 KB · Views: 62

n3wguys

Registered User.
Local time
Today, 08:36
Joined
May 14, 2012
Messages
39
Thank you very much...

I have saw the program and there need to setting up in primary key by you setting and code, and this is very nice. But if we want to write full code in vba without setting as like you do before, how to do with code?
 

JHB

Have been here a while
Local time
Today, 17:36
Joined
Jun 17, 2012
Messages
7,732
.. But if we want to write full code in vba without setting as like you do before, how to do with code?
I've only to ask WHY, (when MS-Access does it for you)?
And what is for you full code?
 

n3wguys

Registered User.
Local time
Today, 08:36
Joined
May 14, 2012
Messages
39
Honestly, I want to know how to write with ADO Object code with vba.

usually I use the code example in vb6:

...
.lockType= .....
.open "select * from ..... where noregister = ' " & blablabla & "' and code_machine = '" & blabla &"'",conn

if not .EOF then
msgbox_warning_will_be_show
else
.add
.update
end if
......


so from there, I want to write full vba code as like vb6. and I know, vba and vb6 code is a few different and nothing enough reference that I have.

so how to write like that in vba ?:banghead:
thanks
 

JHB

Have been here a while
Local time
Today, 17:36
Joined
Jun 17, 2012
Messages
7,732
Okay - I'll give you 2 samples.

Code:
  Dim dbs As Database, rst As Recordset
  
  Set dbs = CurrentDb
  
  Set rst = dbs.OpenRecordset("SELECT Count(Id) AS CountOfId " _
  & "FROM Table1 " _
  & "WHERE Noregister='" & Me.Noregister & "' AND CodeMachine='" & Me.KodeMachine & "'")
  If rst![CountOfId] = 0 Then
    DoCmd.RunCommand acCmdRecordsGoToNew
  Else
    MsgBox ("Data Duplicate!")
  End If
Code:
  Dim a As Integer
  
  a = DLookup("count(id)", "Table1", "Noregister='" & Me.Noregister & "' AND CodeMachine='" & Me.KodeMachine & "'")
  If a = 0 Then
    DoCmd.RunCommand acCmdRecordsGoToNew
  Else
    MsgBox ("Data Duplicate!")
  End If
 

n3wguys

Registered User.
Local time
Today, 08:36
Joined
May 14, 2012
Messages
39
Dear JHB,

Thank you so much... the code very nice..simple and ....(i dont know how to thank to you) :)

Now, I already know how to use that the DLookup function or DAO programming,
It could be write two condition or more may be. Thank you so much...:)

Happy weekend
 

Users who are viewing this thread

Top Bottom