Hi I have a problem with my code: I have two windows form Menu and Login. I set Menu as MdiParent.
So this is what it looks like.
My problem is when I log in as Clerk I want User Account to be disbled. My code in Login Form is this:
If myReader.Read Then
MsgBox("Log-in Successfully", vbInformation, "Log-in")
If cmbtype.Text = "Clerk" Then
Menu.useracc.Enabled = False 'but i got an error here
Else
Menu.useracc.Enabled = True 'same as here
End If
Me.Close()
clear()
Else
MsgBox("Username and Password do not match. Please check and log-in again.", vbCritical, "Log-in Failed")
End If
What would be the right code to disable menu item from my Menu Form when Login Form closes.
Related
I have a program that needs credentials to be added to a log on form before the main form can be displayed. See code:
If loginSuccess = True Then
'Me.UseWaitCursor = true
If wincheck.Checked = True Then
loggedinUser.currentUser = Environment.UserDomainName & "\" & Environment.UserName
Else
loggedinUser.currentUser = usernametxt.Text
End If
Mainfrm.Show()
Me.Close()
'Me.UseWaitCursor = false
Else
MsgBox("Login failed. Please check your credentials.")
End If
The issue is, once the credentials are entered and the mainform begins to load in, there is no indication that the mainform is loading. I feel like a splash screen is unnecassery because it only takes around 5 seconds to load.
I either want the mouse icon to change to indicate something is loading, or I want a loading icon to be displayed over the login form.
Any ideas?
In access I am trying to not let the user exit a textbox unless they have filled it out (i.e. not left it null). This is to be done in a function in order to cut down on code. In VBA is there some way to stop the user from exiting the function? (I know about setting the focus but I need the code to work from a multitude of different textboxes)
For reference my current code is as follows;
Function Reload()
If IsNull(EmployeeID.Value) Or IsNull([First Name].Value) Or IsNull([Surname].Value) Or IsNull(DOB.Value) Or IsNull(Position.Value) Or IsNull(Position.Value) Or IsNull(Mobile.Value) Or IsNull(Email.Value) Or IsNull(Address.Value) Or IsNull(Suburb.Value) Or IsNull(Postcode.Value) Or IsNull([Start Date].Value) Or IsNull(UserLogin.Value) Or IsNull(UserPassword.Value) Then
MsgBox "Please fill out all fields"
Else
DoCmd.RunCommand acCmdSaveRecord
Form.Refresh
End If
End Function
Thanks
The best technique I know is to use the BeforeUpdate event to run data validation. Using your if statements if the data is not valid then set
Cancel = True
and the data will not write. You would probably prefer to disable the default record navigation and form close buttons and use custom buttons so that you can trap the invalid data error and prevent moving to a new record or closing the form. But even if you allow the user to use the built in navigation buttons or close button Access will throw up error messages about being unable to save the current record and prompt the user if he wants to proceed.
You can also go a step further and captue which fields are invalid and present a message box.
Msgbox ("The following fields were left blank and must be entered to save this record:" & vbCrLf & "Field 1" & vbCrLf & "Field 2")
A little modification of the text input limiter i use in our chat room should help. New function I have called it MustINPUT and call it on the LostFocus of the text boxes that you don't want to move from with out input.
Private Sub MyTextBox_LostFocus()
Call MustINPUT (Me.MyTextBox, 0)
End Sub
Just change the message for your users.
Sub MustINPUT(ctl As Control, iMaxLen As Integer)
'Call MustINPUT(Me.txtSayThis, 0)
If Len(ctl.Text) = iMaxLen Then
MsgBox "Please Type something", vbExclamation, "Input Needed"
ctl.Text = Left(ctl.Text, iMaxLen)
ctl.SelStart = iMaxLen
End If
End Sub
Hope this help. DR ,
I have the following code on a subform's on current, but it errors on open of the main form:
If IsNull([Forms]![frmMContacts]!ID) Then
With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
.Enabled = False
End With
Else
With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
.Enabled = True
End With
If Me.NewRecord Then
Me.txtCurrRec = "New Contact Role Record"
Else
Me.txtCurrRec = CStr(Me.CurrentRecord) & " of " & _
DCount("ID", "tblContactPeople", "FKClient = " & Me.Parent.CM_CID) & " Contact Roles"
End If
End If
The point of it is, simply to update a text box in the form's footer, to provide a count of records for the sub form. The issue is that when a user opens the main (parent) form, from the main menu, the main record has no record, and the sub form is still loading. In reality, I'm hiding the detail of the main form, and hence this sub form is hidden. The user has to hit 1 of 2 buttons in the main form header. Either find a record (pop-up form) or start a new one (another pop-up form).
When I try to open this main form, I get the error "run-time error '2465' application-defined or object-defined error".
I'm not sure how to trap this and just either make the sub-form disabled or prevent this on-current code form firing, until the parent has a record.
Thanks for any help!
So, I literally have one more thing to do to finish my Calculator, which is make an error box popup if the textbox is empty. Currently, it shows a message, saying an error has occurred. I want it to simply launch a popup if the textbox is empty, and a "Continue" button to close the window.
If you want a simple popup, try this:
if textboxNum1.Text = "" OR textboxNum2.Text = "" Then
MsgBox("Textboxes are empty!")
else
'Enter process here
End if
Or try this:
if(textboxNum1.Text = "" OR textboxNum2.Text = "") Then
MsgBox("Textboxes are empty!")
else
'Enter process here
End if
I'm trying to make a loading screen with messageboxes, but you have to click the OK button... which I don't think anyone likes.
I want to make a program that will open the messagebox then wait for about 1 or 2 seconds, then open the next one and keep doing it until the loading is complete, here's the code I have so far.
Dim result = MessageBox.Show("Loading.", "Loading Form", MessageBoxButtons.OK)
If result = DialogResult.OK Then
MessageBox.Show("Loading..", "Loading Form", MessageBoxButtons.OK)
If result = DialogResult.OK Then
MessageBox.Show("Loading...", "Loading Form", MessageBoxButtons.OK)
If result = Windows.Forms.DialogResult.OK Then
MessageBox.Show("Loading Complete.", "Loading Complete", MessageBoxButtons.OK)
End If
End If
End If
Anyone have a solution?
If the message box is just a way of letting users know where the process is, it's best to just give them a progress bar or update a label on the form with your message. In addition, turn on the hour glass so users know that the program is still executing.