Simple: How To Use This Code With Switchboard Button
Feb 3, 2005
I found this simple password code that I use to open some forms:
Code:Dim x As Stringx = "password"Dim y As Stringy = InputBox("Enter password for form")If x <> y ThenMsgBox ("Invalid password")DoCmd.CancelEventEnd If
I would like to use it in a switchboard button, but the following statement is
OnClick already "=HandleButtonClick(4)". How can I incorporate this statement
with the code?
(I guess I don't really understanding how the auto-switchboard works.)
Works great, but when I hit the number "3", (3 times in row) it will let me into the form. I want it to not let me in IF I don't know the password.
Where did I go wrong?
Private Sub Form_Load() Dim pw As Variant
If InputBox("What is the password?", "Password") = "1" Then Else MsgBox "Invalid Password", vbCritical, "Sorry Charlie" DoCmd.Close If InputBox("What is the password?", "Password") = "2" Then Else MsgBox "Invalid Password", vbCritical, "Sorry Charlie" DoCmd.Close End If End If
Attached is a simple Outlook Type of Switchboard that I was playing around with. This switchboard does not use ActiveX like others that I have seen out there.
If you improve on this simple switchboard could please post it back for others in in the forum. I would like to know what people think about this simple swtichboard.
Is there anyway to set differentbutton images for each section of a switch board.
Say I have a main switch board with "Customers", "Orders" and "Products". I want each one of these buttons to have an image.
However, when you click on "Customers" you go to the customers swicthboard, which then has "add", "delete" and "edit". I would like these three buttons to have images, but different images to those on the main form.
is it possible to create a back button on your switchboard so from your main switchboard your subwitchboards or your sub sub switchboards you just click the back button to go the the previous switchboard?
I have created a database where my boss wants a password on the one button to limit access. Is this possible. The button actually opens the Database Window (no one else knows the bypass to open it F11)
hello, I have a main switchboard that has a button which opens another switchboard, the button is labelled (has the caption) “Reports” but the trouble is when this other switchboard opens the button on here also has the name “reports” but I want it to be named: “open employee report” and if I change the name of the button on the other switchboard it changes it on both switchboards :mad: , anyone know of a way around this?
Hi! Everyone on this forum has been very helpful so far, and I could really use some expertise now. I'm trying to update an existing DB designed by someone else (no longer here). I need to add a button to the switchboard for 2006, but I don't understand the code that has been written for the form I am trying to update. I've posted the code below. If anyone can help me decipher it enough to add my button, I would really appreciate it. My new button should be the 9th one. Thanks in advance:
Private Sub Form_Open(Cancel As Integer) ' Minimize the database window and initialize the form.
' Move to the switchboard page that is marked as the default. Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' " Me.FilterOn = True
End Sub
Private Sub Form_Current() ' Update the caption and fill in the list of options.
Me.Caption = Nz(Me![ItemText], "") FillOptions
End Sub
Private Sub FillOptions() ' Fill in the options for this switchboard page.
' The number of buttons on the form. Const conNumButtons = 9
Dim dbs As Database Dim rst As Recordset Dim strSQL As String Dim intOption As Integer
' Set the focus to the first button on the form, ' and then hide all of the buttons on the form ' but the first. You can't hide the field with the focus. Me![Option1].SetFocus For intOption = 2 To conNumButtons Me("Option" & intOption).Visible = False Me("OptionLabel" & intOption).Visible = False Next intOption
' Open the table of Switchboard Items, and find ' the first item for this Switchboard Page. Set dbs = CurrentDb() strSQL = "SELECT * FROM [Switchboard Items]" strSQL = strSQL & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID] strSQL = strSQL & " ORDER BY [ItemNumber];" Set rst = dbs.OpenRecordset(strSQL)
' If there are no options for this Switchboard Page, ' display a message. Otherwise, fill the page with the items. If (rst.EOF) Then Me![OptionLabel1].Caption = "There are no items for this switchboard page" Else While (Not (rst.EOF)) Me("Option" & rst![ItemNumber]).Visible = True Me("OptionLabel" & rst![ItemNumber]).Visible = True Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText] rst.MoveNext Wend End If
' Close the recordset and the database. rst.Close dbs.Close
End Sub
Private Function HandleButtonClick(intBtn As Integer) ' This function is called when a button is clicked. ' intBtn indicates which button was clicked.
' Constants for the commands that can be executed. Const conCmdGotoSwitchboard = 1 Const conCmdOpenFormAdd = 2 Const conCmdOpenFormBrowse = 3 Const conCmdOpenReport = 4 Const conCmdCustomizeSwitchboard = 5 Const conCmdExitApplication = 6 Const conCmdRunMacro = 7 Const conCmdRunCode = 8
' An error that is special cased. Const conErrDoCmdCancelled = 2501
Dim dbs As Database Dim rst As Recordset
On Error GoTo HandleButtonClick_Err
' Find the item in the Switchboard Items table ' that corresponds to the button that was clicked. Set dbs = CurrentDb() Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset) rst.FindFirst "[SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
' If no item matches, report the error and exit the function. If (rst.NoMatch) Then MsgBox "There was an error reading the Switchboard Items table." rst.Close dbs.Close Exit Function End If
Select Case rst![Command]
' Go to another switchboard. Case conCmdGotoSwitchboard Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rst![Argument]
' Open a form in Add mode. Case conCmdOpenFormAdd DoCmd.OpenForm rst![Argument], , , , acAdd
' Open a form. Case conCmdOpenFormBrowse DoCmd.OpenForm rst![Argument]
' Open a report. Case conCmdOpenReport DoCmd.OpenReport rst![Argument], acPreview
' Customize the Switchboard. Case conCmdCustomizeSwitchboard ' Handle the case where the Switchboard Manager ' is not installed (e.g. Minimal Install). On Error Resume Next Application.Run "WZMAIN80.sbm_Entry" If (Err <> 0) Then MsgBox "Command not available." On Error GoTo 0 ' Update the form. Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' " Me.Caption = Nz(Me![ItemText], "") FillOptions
' Exit the application. Case conCmdExitApplication CloseCurrentDatabase
' Run a macro. Case conCmdRunMacro DoCmd.RunMacro rst![Argument]
' Run code. Case conCmdRunCode Application.Run rst![Argument]
' Any other command is unrecognized. Case Else MsgBox "Unknown option."
End Select
' Close the recordset and the database. rst.Close dbs.Close
HandleButtonClick_Exit: Exit Function
HandleButtonClick_Err: ' If the action was cancelled by the user for ' some reason, don't display an error message. ' Instead, resume on the next line. If (Err = conErrDoCmdCancelled) Then Resume Next Else MsgBox "There was an error executing the command.", vbCritical Resume HandleButtonClick_Exit End If
I am checking to see if a memo field and/or a text field has more than 1000 characters and if so then it calls a function that prints legal size paper vs. 8 X 11. It works fine except when the either field is empty. I have searched and searched the Forum and found many that are close but no cigar!
I know this involves a "IsNull" routine and I know I need to check both fields but can't quite come up with the right syntax. Right now if either field is empty I get an error msg = "Invalid use of Null"
Could someone please help?! Thanks in advance once again! This is the basic code after setting the focus,etc....
So far I have a query that picks up any collisions between booking dates with the following:
SELECT [Customer Details].[CustomerID], [Booking].[RoomNumber], [Booking].[DateFrom], [Booking].[DateTo] FROM [Room Details] INNER JOIN ([Customer Details] INNER JOIN Booking ON [Customer Details].[CustomerID]=[Booking].[CustomerID]) ON [Room Details].[RoomNo]=[Booking].[RoomNumber] WHERE DateFrom Or DateTo Between [Forms]![Bookings]![DateFrom] And [Forms]![Bookings]![DateTo] And ([BookingID]<>[Forms]![Bookings]![text38]) And (RoomNumber=[Forms]![Bookings]!RoomNumber) ORDER BY [DateFrom] And [DateTo];
But the problem is that it doesn't pick up dates inbetween DateTo and DateFrom. So:
Booking 1 12/12/06 20/12/06
Booking 2 13/12/06 19/12/06
On trying to book Booking 2 it will not notify me of 'no clashes' when there are. As it isn't passing by the 12th or 20th my SQL doesn't pick it up.
Can anybody help me? I'm new to code so I'm probably missing the obvious but all help will be greatly appreciated.
Is it possible to create a command button on an Access switchboard that will automatically backup a database? What code would I need? The command button wizard doesn't handle this task.
I have a database with 8 tables. One of these being staff
I have staffID as a Primary key in the table staff The format of this is "STA"0000 and input mask "STA"9999
I would like staffID to be automatically generated by taking the value of the previous staffID (eg STA0001) and creating a new staffID for the next member of staff that is to be added (eg, STA0002).
I have access experience but have never had to use SQL code and am struggling. If anyone could be kind enough to help me with this I would be very grateful.
Just arrived here, so I hope this question is in the correct forum. Here is my question
I have one field called ContractType, another field called Contract Description. What I like to do is if ContractType = CO and Contract Description, DO NOT HAVE TEXT IN THE Contract Description field, flash the Contract Description field. How do I identify if there is text fill out in the Const_Description field?
This is what I have so far:
Private Sub Form_Timer() If Me.ContractType = "CO" Then Me.Const_Description.Visible = True Else Me.Const_Description.Visible = Not Me.Const_Description.Visible End If End Sub
I hope I made this easy to understand. Very new at Code.
I got this to work easily on another form but on this particular form it doesnt work. I enter a command button and name it d1, then I enter this code for it to populate the current date in the field next to the box:
Private Sub d1_Click() Date_Entered.Value = Date End Sub
Can anyone see why it doesnt work :eek:
ERROR IS: Run-time error '2465':
Database cant find the field 'Date' referred to in your expression.
When I enter a date field it enders whats in that field (blank) into the field I told it (Date_Entered) on my form.
I have some simple validation that unit price is greater than 0. The code is this:
If Me.txtUnitPrice.Value <= 0 Then MsgBox "Please enter a value greater than zero", vbOKOnly, "Alert" Me.txtUnitPrice.Value = Null Me.txtUnitPrice.SetFocus End If
However, when I run it, the setfocus doesn't work. It jumps straight into the next field. I can make it run to any other field (productname, productID). But not back to UnitPrice.
quick easy question, as im a noob when it comes to coding/vb.
Within our company database we have the usual timesheet table. With the table I have create a query (called "dailytimeforkeith") that gives me the sum of time for an individual person for one day (in fact its the previous day). What I have done then is created a form (called "keithyesterdaytime") that shows this query entry (called "sumoftimespent").
Each user has a different database screen logon and forms that are present when they log in. So what I then done is on one of these forms the load up, i attached this:
Private Sub Employee_Enter()
Me.Employee = User.FirstName
If Me.Employee = "Keith" Then
Dim stdocname As String
stdocname = "keithyesterdaytime"
DoCmd.OpenForm stdocname, , , acAdd
............
then on "keithyesterdaytime" opening the following code runs ------------------------------------------------------------
Hi, I have a DAP with a command button at the end that saves the record. I'd like to have a confirmation message or text box that tells them their data was saved and then close the browser when they click OK.
Sounds like a macro or procedure might be the way to go...but I am not proficient in VB and not sure how to attach it to the command button. Any help would be great!
Let me describe the database briefly. I have a table with two fields, item and score. Item's data type is text, and score's data type is number.
I have a form with two combo boxes and a button and some other controls. I need code for the button.
When I select an item in combo1 and another item in combo2 and then click on the button, I want the score for the item in combo1 to be one greater than the score of the item in combo2. Also, if the score of any other item is greater than or equal to the score of combo1, I want the score for each of those items to increase by one.
This is code in a command button on a form to preview a report. DoCmd.OpenReport stDocName, acViewPreview, "Control Room Query", "[Lot #] = Forms![Hydro COA]![LotNumber]" What could I change in this code to use in a different command button to have the report sent as an attachment in snapshot format in an email? The user would have to fill in the address, subject and body of the email. Thanks much!
I am designing a form and I need to add a Browse button to it. I need the Browse Button to point to the "My Computer". Once that file is selected I need it to fill in the hyperlink box. I have the hyperlink text box on the form and it works if you manually type a link in. I would like it to auto fill-in with the selected file.
I have two text boxes and a check box - so the user can enter (1) patient weight, (2) patient height and then check whether the patient is male or female. The first two are then used to calculate a Body Mass Index. (simple enough and works OK). What I then want to do is have four command buttons that become visible when the calculation is within a certain range. So - simplistically- if the calculation (calctxtbox) is between 0 and 5 AND the patient is female then the command button called "normal"(Command79) is enabled. My VB code writing is improving (thanks largely to this forum!) but still very basic - can some-one help please?
Do I put my code in the "after update" event of the calctxtbox?
Private Sub calctxtbox_AfterUpdate() If calctxtbox > 0 (How do I say and <5) and then how do I say Female =Yes Then Command79.Enabled = True End Sub Am I close? Also can you enable labels and text boxes or just buttons.
Hi! I have a cmd Button in a form that onclick is suppose to open the selected record in a specified form. My problem is when the specified form opens it doesn't have any data in it. Any thoughts would be much appreciated!! Here is the cmd button code i used:
Private Sub Command14_Click() On Error GoTo Err_Command14_Click
Dim stDocName As String Dim stLinkCriteria As String
Does anyone know the code for opening a specific notepad file from a button? I know there's a default button but it only opens a blank notepad page. I need to open some written instructions from a button you see.
I have created command buttons to enter event registration information after biographical information has been completed. When I click on the button I get the following error message:
"Microsoft Office Access cannot find the field '|' referred to in your expression."
This is the On Click code that I have in there. Can anyone spot the error of my ways?
Private Sub RegisterButton_Click() On Error GoTo Err_RegisterButton_Click If IsNull(Me![AttendeeID]) Then MsgBox "Enter attendee information before registering for an event." Else DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 DoCmd.OpenForm "Registration", , , "[Registration]![RegistrationID]=Forms![Attendees]![Attendees Subform].form![RegistrationID]" End If
Exit_RegisterButton_Click: Exit Sub
Err_RegisterButton_Click: MsgBox Err.Description Resume Exit_RegisterButton_Click End Sub