Modules & VBA :: How To Validate That At Least One Checkbox Is Selected
Apr 13, 2014
I am trying to validate that the user selects at least one checkbox out of three on the form in Access 2010. They can select one, two or even all three if they wish, but at least one must be checked. I am using the following code attached to the click event of a command button. It was fine but seems to have stopped working. The control names are generic to illustrate my code. The form is unbound:
if (chk1 + chk2 + chk3) = 0 then
Msgbox "Please select at least one checkbox"
exit sub
end if
Can I look up and verify data on a "second" form based on a selected record from first (still open) form.
I am trying to allow users to select a User Name from a combo box list and then open "Change Password" form when they select "Change Password" for that selected user name.
My problem is that I can't figure out how to associate and verify the data tied to the user name selected on the previous (Login) form ( I am trying to validate the old password tied to that selected record).
I have the first login form created, and it's working just fine. I also have the change password form created (and it's displaying the user name selected from the first form using:
Code: Private Sub Form_Load() With Forms![frmLogin]![cboUserName] Me.txtPwdChgUserID = .Column(2, .ListIndex) End With EndSub
I also have the code written to validate and confirm old password, new password and validate new password (when the save button is clicked). I have yet to update the password with the new password (still trying to figure that out).
Attached zip file has screen shots of the two forms.
I have the following code which works perfectly BUT I want to be able to add another line of text if users enable a checkbox. I have tried everything I can think of but can't get it to work. When using an "IF check150" statement it just adds the extra text in regardless of selection or not.
Code:
Function Mail_Radio_Outlook6(activedoc As String) Dim OutApp As Object Dim OutMail As Object Dim strbody As String Dim acc_req As String Set OutApp = CreateObject("Outlook.Application")
[Code] ....
This is fine most of the time but If a user ticks check150 I want to add another paragraph.
Do I use an IF statement, if so in what format? is it a separate function etc?
I am slowly getting more familiar with Access but still come unstuck on the simplest of things at times.
Hi i have a shared database and have a form with a string of records. Each record has its own unbound checkbox and I want to make it so you can select multiple records, then be able to hit a button on the top of the form to edit certain fields of the records selected. Please keep in mind that this is shared by 10 users, therefore a linked yes/no field would cause problems between the users.
I have a textbox where I need an afterupdate event, which should check that input is 3 letters followed by 3 numbers. The total is 6 characters, but always 3 letters + 3 numbers. If condition not met, a msgbox will be shown, for the user to input correctly, before being able to continue.
I have a table called 'Klanten' which contains the rows 'password' and 'login' (and several rows not needed for this form)
So I'm trying to make a login form which first checks if something is entered (this part of the code seems to work).
Private Sub Knop13_Click() 'Check to see if data is entered into Username If IsNull(Me.Username) Or Me.Username = "" Then MsgBox "gelieve een login in te voeren.", vbOKOnly, "Required Data" Me.Username.SetFocus
[Code] ....
But from then on i seem to have some issues.. The part of the code underneath seems to only work for the first 'login' and 'paswoord' in my table called "Klanten".
-Username is the name for the field where they enter their 'login'. -Password is the name for the field where they enter their 'paswoord'
If Username.Value <> DLookup("[login]", "Klanten", "[Username]='" & Username & "'") Then MsgBox "Invalid Username. Please try again.", vbOKOnly, "Invalid Entry!" Exit Sub End If
If Password.Value <> DLookup("[wachtwoord]", "Klanten", "[Password]='" & Password & "'") Then MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Entry!" Exit Sub End If
Then as last part i would like to goto another form called 'Mainmenu' if both the Login and the Paswoord is correctly entered in the fields Username and Password. Here i have the most issues as this doesn't seem to do anything at the moment
If Password.Value = DLookup("[wachtwoord]", "Klanten", "[Username]='" & Username & "'") And Username.Value <> DLookup("[login]", "Klanten", "[Password]='" & Password & "'") Then DoCmd.OpenForm "Mainmenu" End Sub
I am trying to write following code, I want Msg to pop, when all three condition are true, but it not working
'''Non Budgeted Projects need Explanation and Variance class"
If Me.ID.Value >= 90000 And and Me.Variance_Class = "" and Me.Comments_Explanation_Delta_____100K = "" Then
MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..." CheckRules = False GoTo Exit_CheckRules
I'm new to access vba and I'm trying to create a login form. I have already my code to login but i want to validate the password in 'case sensitive' basis. Below is only what I've got so far.
Code: Private Sub cmdLogin_Click() Dim login_validation As Variant login_validation = DLookup("Password", "tblLogin", "Username='" & Nz(txtUsername.Value, "") & "'") If Nz(login_validation, "") <> Nz([txtPassword].Value, "") Then MsgBox "Incorrect Password. Please try again." txtUsername.Value = "" txtPassword.Value = "" txtUsername.SetFocus Else MsgBox "Hi " & txtUsername.Value & "," & vbNewLine & vbNewLine & "you have successfully login!" DoCmd.OpenForm "frmMain" End If End Sub
I am having an issue using DCount to validate against 3 fields within my database. I have a booking form which contains a Staff member, viewing slot, and Viewing Date which is used to book property viewings.
I want the form to check that the booking doesn't already exist when the process booking button is pressed.
I am using the following statement:
Code: If DCount("*", "Viewing", "[Staff_ID]=" & Me.[Staff_ID] & " AND [Viewing_Period] = " & Me.Viewing_Period & "' AND Viewing_Date = '" & Me.Viewing_Date) & "'" > 0 Then MsgBox "Cannot book, booking already exists", vbCritical End If
I always get the error "Syntax Error (Missing Operator)".
I am trying to figure out how to control a navigation tab with a checkbox. I have a database for my fire dept and the check box is called "deceased". When a member passes away, the active box gets unchecked and deceased gets checked. Under the member subform, there is a tab, navigationbutton19, that is called deceased also and under this tab all their burial information is stored. What I am trying to do is, if the checkbox is not checked, I want the tab to be enabled = false.
I have the following module which displays the backcolor of a checkbox label if it is true or false
Private Sub FormatLabel(chk As Control) With chk.Controls(0) If chk Then .BackColor = vbYellow .BackStyle = 1 .ForeColor = vbRed
[Code] .....
Which works great! But I cannot figure out how to make it work in the control AfterUpdate Event. I tried using it in the current control's (checkbox) after update event
Dim itm As Control If itm.ControlType = 106 Then FormatLabel itm
but nothing happens (no change, no error message).
I have tried creating a new module:
Public Sub CheckBoxFormat(chk As Control) If chk = -1 Then chk.BackColor = vbYellow chk.BackStyle = 1 chk.ForeColor = vbRed Else chk.BackColor = vbWhite chk.ForeColor = vbBlack End If End Sub
But when I try to call it in the AfterUpdate event for the particular checkbox
Private Sub CheckBoxA_AfterUpdate() Dim itm As Control If itm.ControlType = 106 Then CheckBoxFormat itm End Sub
I get the error message "Expected Variable or Procedure not module"
So, (1) is my module all wrong or (2) am I calling it incorrectly or (3) wrong on both items?
I have some code that creates queries based on a value in a checkbox.
So, depending on that value, the queries may or may not exist.
I need to take those queries (if the exist) and create one union query.
This code creates the first query beautifully, but it won't union the second query.
Code: Private Sub cmdSubmit_Click() Dim blnQueryExists As Boolean Dim cat As New ADOX.Catalog Dim cmd As New ADODB.Command Dim qry As ADOX.View blnQueryExists = False
When you update inspection requested the inspection due is automatically updated to 30 work days from that day.
Now what I'm trying to do is get the overdue field (it's a yes/no field) to automatically check itself when the current date is passed the inspection due and the inspection done field is blank.
Here's what I have that isn't working:
Code: Private Sub Form_Current() If DateAddW([REQUEST], 30) < Date And [INSPECT DONE] = 0 Then [OVERDUE] = True End If End Sub
DateAddW is a UDF that works just fine. I've tried replacing 0 with Null and neither works.
I'm using the OnLoad event of a form I've got as a placeholder to load a report from the onclick event of a button on my continuous form, and loading a chkbox into the code as a string variable.For some reason, when the DB automates the procedure, I get a 'Type mismatch' error appear, but when I step through the code using F8 it works.
when I press F5 after the code has stopped I get the 'Type mismatch' error.The chkbox contains a value of '-1', and I've used debug.print to return the TypeName and VarType values, which were 'String' and '8' (which I took to mean 'String') respectively.
There are other variables being declared in the code, and I commented out the whole lot and put each one back in individually before running the code as a process of elimination, and the checkbox was the one that threw up the error again.
Code:
Dim Prod1stSend as String Prod1stSend = me.chkProd1stSend
We are using the code to determine whether our clients have been contacted by us before, as this will decide which report is opened. I've tried setting the variable as Boolea and Variant too, and both of those still throw up the same error.
I'm trying to find a code that will allow me to check a value of a yes/no checkbox based on a username.
What I want to happpen is:
1. The code looks to see if the username that is entered in "txtUsername" field on the form matches the "empUsername" value on the table "tblUsers." 2. If there is a match, I want it to look at the value for the field "Admin" on "tblUsers" to see if the value is checked as true. 3. If the value is true, I want it to open a specific form "frmAdmin." If it is false, I want it to open a form "frmMain."
VBA codes not recognizing the Admin field and instead taking all users into the frmMain.
I've got a form (frmEdit) that allows users to search tblMain for records using a bunch of unbound controls and a dynamically created SQL statement. Search results are displayed in a subform (subMain), and the current record in the subform is displayed in a set of bound controls on frmEdit.
Now the important bit: There is a set of unbound checkboxes on my form that allow the user to change which fields are visible in subMain. This is accomplished by the following:
Code: Private Sub chkName_AfterUpdate() If Me.chkName = 0 Then Me.subMain.Form.CorrespondingField.ColumnHidden = True Else Me.subMain.Form.CorrespondingField.ColumnHidden = False End If End Sub
Certain fields are visible by default, but the user may want to change which fields those are. Here's what I've done so far to accomplish this:
Created a button (btnChangeDefaults) that opens a form (frmChangeDefaults)
Put checkboxes for each table field on frmChangeDefaults
Put a "Cancel" button (btnCancel)* and "Done" button (btnDone)** on frmChangeDefaults.
*btnCancel just closes frmChangeDefaults without making any changes to frmChangeDefaults or frmEdit
**btnDone changes Forms.frmEdit.Form.chkName.DefaultValue to Me.CorrespondingCheckBox.Value and then closes frmChangeDefaults
This all seems to work quite well, actually. Debugging confirms that the default values of the checkboxes on frmEdit are indeed changed when I click btnDone. But when I close frmEdit and re-open it, the default values return to what they were prior. This happens even when:
I close frmEdit using DoCmd.Close acForm, "frmEdit", acSaveYes
I close frmEdit after using DoCmd.Save acForm, "FrmEdit"
I save frmEdit manually by right-clicking and pressing save
I have combo box call "supervisor" and check box call "supervisorchange" basically want to make supervisor change to true if combo box is change which I have made code you can see below it work's
Code: Private Sub Supervisor_Change() If Me.Supervisor = "" Then Me.SupervisorChange = False Else Me.SupervisorChange = True End If End Sub
right now my problem, prob easy fix for you access experts
If the supervisor combo box is empty and user inputs a supervisor I would like the supervisor change check box not to change to true
only if the user changes it after the first input I would like the supervisor change check box to become true
My subform consists of a list of tasks that are waiting to be verified. in order to verify tasks, the user scrolls through the list of tasks and checks a checkbox (discrepancyverified) on each record they wish to verify. After the user has finished checking all the records they wish to verify, they click a verify button on the main form which should then go back through each record and update the verifieddate value of any that are checked to today.
This is what I have so far:
Code:
Private Sub Command19_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Dim ctl As Control Dim varItem As Variant
I have a field 'Payment Types' with values (Cash, Cheque, Debit/Credit Card) and a field 'Payment Received' which is Yes/No.
When putting the order through the user selects the payment type and ticks a box if payment has been received.
On a report for delivery drivers, the owner wants it simple for the driver... he wants all the payment types listed with a checkbox next to each one, then wants the appropriate box ticked if payment has been received.
So I need something on the report (or underlying query) which ticks the appropriate box, i.e.
If payment received = true then payment type checkbox = true.
Or should I put the payments into a separate table with both fields so multiple payment types can be marked as paid?
I have code which is attached to onclick of a checkbox,
What I want it to do is if the user clicks it and checks it then to add some note to a memo field, if the user clicks it and its already checked then it doesn't add a note to a memo field.
Code: Private Sub Check45_Click() If Check45 = 0 Then Check45 = 1 If Len([Forms]![Customer]!Notes.Value & "") = 0 Then
[Code] ....
But I can't seem to add any other lines which make sense to me that it doesnt add "letter sent" to a memo field if its already checked?