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
415 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
 

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
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)

 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
ID: 33460970
what name did you give to your append query?
0
 
LVL 119

Accepted Solution

by:
Rey Obrero 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now