Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
436 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

877 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