Sep 16 2024 03:13 AM
Help with the best strategy to prevent workbook flash before Login form displays
Sep 17 2024 01:23 AM
@Muhammadiyya I'm afraid you are giving us too little information to be of real help. Kindly provide us with:
Sep 17 2024 02:11 AM
Sep 17 2024 04:42 AM - edited Sep 17 2024 04:50 AM
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 Sub
In 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 If
Finally, do not hide the application window (remove any Application.Visible = false)
Sep 22 2024 02:28 AM
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 Sub
or if it can be modified to work for comboboxchange event but not prompting save for each students. thanks
Sep 23 2024 02:14 AM
Sep 23 2024 02:26 AM
i don't understand sir, or probably the settings on my excel print page could cause the save as to always prompt?.
or can this occur when no printer is connected to the system?@JKPieterse
Sep 24 2024 12:53 AM