Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to create conditional onclick event in MS Access 2007 - Check DB if values selected exist or not

Posted on 2010-08-17
9
422 Views
Last Modified: 2012-06-27
Hello experts,
I have a form (Form1) which has 4 combo box and a button, once the user clicks the button what i wanted to happen (in order)....
1.0 Checks the database if the values (all selected) does not exist in my table (tbl1)
                   2.1 If values exists then open Form2
                   2.2 If values does not exist then run append query (insert records to tbl1) then open form3.
Is this possible? If yes, id appreciate some example or links to learn how to do it.
Please feedback if the thread needs to be broken down into multiple questions
0
Comment
Question by:jsuanque
  • 5
  • 4
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33460690
can you upload a copy of the db?

the field names to search on are important here for each combo boxes selected items..
0
 

Author Comment

by:jsuanque
ID: 33460773
Hello capricorn1,

The table it needs to check (and eventually be appending) is T_ASSESSMENT_MONITORING and the form i need help is just Form1.
Honestly i,m not comfortable in uploading the db since it already got some confidential info inside.
Anyway, i hope this helps....
Form1.Combo1 check against T_ASSESSMENT_MONITORING.col1
Form1.Combo2 check against T_ASSESSMENT_MONITORING.col2
Form1.Combo3 check against T_ASSESSMENT_MONITORING.col3
Form1.Combo4 check against T_ASSESSMENT_MONITORING.col3
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33460878
are you going to check the combination of all the combo boxes?
i am assuming that all the fields are Text Data type

if dcount("*","T_ASSESSMENT_MONITORING","Col1='" & combo1 & "' And Col2='" & combo2 & "' And Col3='" & combo3 & "' And Col4='" & combo4 & "'") > 0 then
    msgbox "record exists"
    docmd.openform "form2"

    else
    currentdb.execute "insert into T_ASSESSMENT_MONITORING(col1,col2,col3,col4) values ('" & combo1 & "', '" & combo2 & "','" & combo3 & "','" & combo4 & "')"

     docmd.openform "form3"

end if
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:jsuanque
ID: 33460954
Actually it should check the combination of all combo boxes. By the way should this just be amended to the other code you provided?
Another thing....
currentdb.execute "insert into T_ASSESSMENT_MONITORING(col1,col2,col3,col4) values ('" & combo1 & "', '" & combo2 & "','" & combo3 & "','" & combo4 & "')"
..how do i utilize my append query for this part...
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33460962
this is the append query

currentdb.execute "insert into T_ASSESSMENT_MONITORING(col1,col2,col3,col4) values ('" & combo1 & "', '" & combo2 & "','" & combo3 & "','" & combo4 & "')"
0
 

Author Comment

by:jsuanque
ID: 33460968
Actually here is my append query...


INSERT INTO T_ASSESMENT_MONITORING ( Year_Group, Student_Rec_ID, NationalUPN, Surname, Firstname, DOB, Gender, Form, Form_Teacher, Assessment_period, Assessment_Category, Assessment_Category_Doc, Assessment_Score, Assessment_Record_Date )
SELECT c.YrgDesc AS Year_Group, a.StuRecID AS Student_Rec_ID, a.StuUPN AS NationalUPN, a.StuSurname AS Surname, a.StuFirstname AS Firstname, a.StuDOB AS DOB, a.StuSex AS Gender, b.clsdesc AS Form, d.PeoTitle & " " & d.PeoInitials & ". " & d.PeoSurname AS Form_Teacher, [Forms]![Form1]![cbo_AssessmentPeriod_FORM1] AS Assessment_period, [Forms]![Form1]![cbo_AssessmentType_FORM1] AS Assessment_Category, [Forms]![Form1]![cbo_AssessmentDocument_FORM1] AS Assessment_Category_Doc, '' AS Assessment_Score, Date() AS Assessment_Record_Date
FROM fStudent AS a, fClass AS b, fYearGroup AS c, fPeople AS d
WHERE (((a.StuClsRecID)=b.ClsRecID) And ((a.StuRollStatus)='C') And ((a.StuYrgRecID)=c.YrgRecID) And ((b.ClsPeoRecID)=d.PeoRecID)) And b.ClsDesc=Forms!Form1!cbo_Form_FORM1
ORDER BY a.StuClsRecID, a.StuSurname;

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33460970
what name did you give to your append query?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 33460993

private sub button_click()
dim ctl as control
   for each ctl in me.controls
      if ctl.controltype=accombobox then
          if len(ctl & "")=0 then
             msgbox ctl.name & " have no value selected"
             me(ctl.name).setfocus
             exit sub
          end if
      end if
  next

'check if record exists
if dcount("*","T_ASSESSMENT_MONITORING","Col1='" & combo1 & "' And Col2='" & combo2 & "' And Col3='" & combo3 & "' And Col4='" & combo4 & "'") > 0 then
    msgbox "record exists"
    docmd.openform "form2"

    else
'run the append query
 
     docmd.openquery "NameOftheAppendQuery"

     docmd.openform "form3"

end if

end sub
0
 

Author Closing Comment

by:jsuanque
ID: 33461029
Great..Great...It worked...Thanks heaps
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question