Forum Discussion
Workbook flash prevent
Muhammadiyya I'm afraid you are giving us too little information to be of real help. Kindly provide us with:
- A clear explanation of what your problem is exactly
- Code you possibly already have that demonstrates the problem
- Even better, a sample workbook with instructions on how to replicate the issue
The login form displays and if the user entered the correct login details, workbook access will be granted but each time I open the work, a sheet flashes before the login form is displayed and that's what I seek help to prevent.
A sample of my project has been sent to your PM thanks
- JKPieterseSep 17, 2024Silver Contributor
Make sure that your workbook contains a new worksheet called "Login" and change the Thisworkbook code to this:
Option Explicit Public LoggedIn As Boolean Private Sub Workbook_AfterSave(ByVal Success As Boolean) If LoggedIn Then HideOrSHow False End If End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) HideOrSHow True End Sub Private Sub Workbook_Open() Application.ScreenUpdating = False Application.DisplayAlerts = False frmLogin.Show End Sub Sub HideOrSHow(justLogin As Boolean) Dim sh As Worksheet For Each sh In Worksheets If LCase(sh.Name) = "login" Then If justLogin Then sh.Visible = True End If Else If justLogin Then sh.Visible = xlSheetVeryHidden Else sh.Visible = xlSheetVisible End If End If Next End SubIn the code behind the userform, make these changes:
' Check if the entered credentials match If txtUserID.Text = userID And txtPassword.Text = password Then MsgBox "Login successful!", vbInformation Unload Me ' Close the login form 'Next two lines are new ThisWorkbook.LoggedIn = True ThisWorkbook.HideOrSHow False ' Show the workbook and the HOME sheet With ThisWorkbook .Windows(1).Visible = True .Sheets("HOME").Visible = xlSheetVisible .Sheets("HOME").Activate End With Application.ScreenUpdating = True Application.DisplayAlerts = True Else MsgBox "Invalid User ID or Password", vbCritical txtUserID.SetFocus ' Set focus back to User ID textbox End IfFinally, do not hide the application window (remove any Application.Visible = false)
- MuhammadiyyaSep 22, 2024Brass Contributor
thanks i just made the adjustment now and it worked perfectly. my system developed an issue which i was able to fix yesterday.
Please i want to directly print each students report cards in sheet(JSS1RC). the students name are populated in combobox1 and the linked cell of the combobox is F2. i used the code below and it prompts save as before each printing. i want the macro to directly print.
here's the code please help modify it to print directly:
Sub PrintReportCards()
Dim ws As Worksheet
Dim combobox As Object
Dim i As Integer' Set the worksheet containing the ComboBox
Set ws = ThisWorkbook.Sheets("JSS1RC")' Set the ComboBox
Set combobox = ws.OLEObjects("ComboBox1").Object ' Adjust ComboBox name if needed' Loop through all items in ComboBox
For i = 0 To combobox.ListCount - 1
' Get the student name from the ComboBox
ws.Range("F2").Value = combobox.List(i)' Print the worksheet
ws.PrintOut
Next i
End Subor if it can be modified to work for comboboxchange event but not prompting save for each students. thanks
- JKPieterseSep 23, 2024Silver ContributorThis code should not trigger any save? Or are you printing to the print to PDF "printer" by any chance?