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
419 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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