Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
434 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
[X]
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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

718 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