I'm trying to use a button for two purposes. Either to add a new record, or to make changing to existing records. I have a button which turns the form into a Data Entry form, then the user can hit the Reset button to change it back to Me.Form.DataEntry = False.
Here is my code: -
Private Sub cmdSave_Click()
-
Dim ctl As Control
-
Dim myForm As Form
-
Set myForm = Me.Form
-
Dim inStorage As Boolean
-
inStorage = False
-
inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
-
inStorage = inStorage Or Me.cboEquipmentStatus.Value = 3
-
If Me.Form.DataEntry = False Then
-
If Me.Dirty Then
-
For Each ctl In myForm
-
If InStr(1, ctl.Tag, "*") <> 0 Then
-
If ctl.Value <> ctl.OldValue Then
-
Me.txtDateUpdated = Date
-
End If
-
End If
-
If InStr(1, ctl.Tag, "&") <> 0 Then
-
If inStorage And ctl.Value <> ctl.OldValue Then
-
If MsgBox("WARNING!! Changing Equipment status to In Storage will remove all Logial Equipment Information as well as the Room its assigned to." _
-
& " Are you sure you want to proceed?", vbYesNo) = vbYes Then
-
Me.txtDateUninstalled = Date
-
MsgBox "Uninstalled Date Updated"
-
Me.Dirty = False
-
Call toStorage
-
Else
-
Me.Undo
-
End If
-
ElseIf Not inStorage Then
-
If IsNull(Me.txtEquipmentName.Value) Or (Me.txtEquipmentName.Value) = "" _
-
Or IsNull(Me.txtEquipmentIP.Value) Or (Me.txtEquipmentIP.Value) = "" _
-
Or IsNull(Me.cboSoftwareVersion.Value) Or (Me.cboSoftwareVersion.Value) = "" _
-
Or IsNull(Me.cboCabinetName.Value) Or (Me.cboCabinetName.Value) = "" Then
-
If MsgBox("If Equipment Status is Operational, Logical Information and Physical Location cannot be blank. Do you want to try again?", vbYesNo) = vbYes Then
-
-
Else
-
Me.Undo
-
End If
-
Else
-
Me.txtDateInstalled = Date
-
End If
-
End If
-
End If
-
Next
-
End If
-
DoCmd.RunCommand acCmdSaveRecord
-
Me.cboBuildingName.ControlSource ="BuildingFK"
-
Me.cboRoomName.ControlSource = "RoomFK"
-
Else
-
DoCmd.RunCommand acCmdSaveRecord
-
Me.frmSubAddEquipment.Requery
-
End If
-
End Sub
-
I noticed the form is not working properly with the "If me.Form.DataEntry = false then" If statement there. It is making changes to the record without validating that all required fields are not null and the msgBoxes are not showing. if I comment out that if statement, it works fine.
What am I doing wrong?
6 1140
I'm a bit confused by lines 45 and 49 as they are saving the record no matter what.
I'm not really sure what you are attempting to do. Wouldn't you validate the record regardless of the Form Mode, Data Entry or Not? And then only allow the save to happen if it passes validation?
Leaving for work soon so don't have time to change things around.
But I'm trying to validate for if the form is in data entry mode. If it is, then I want it to skip to the bottom and save the record. I do need to add some if statements and maybe a boolean to ensure that all required fields are filled in before allowing a user to save the record.
If the form is not in data entry mode, I want users to be able to edit records displayed on the form. And then hit save to save those records.
...Does that make sense?
I sorta understand.
I think what is possibly messing you up is that
will force a save.
I figured it out. Thanks for your help. Now its mostly working and code is maybe 95% complete. -
Private Sub cmdSave_Click()
-
Dim ctl As Control
-
Dim myForm As Form
-
Set myForm = Me.Form
-
Dim inStorage As Boolean
-
Dim addStorage As Boolean
-
If Not IsNull(Me.cboEquipmentStatus.Value) Or Not (Me.cboEquipmentStatus.Value) = "" Then
-
inStorage = False
-
inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
-
End If
-
-
If Me.Form.DataEntry = False Then
-
If Me.Dirty Then
-
For Each ctl In myForm
-
If InStr(1, ctl.Tag, "*") <> 0 Then
-
If ctl.Value <> ctl.OldValue Then
-
Me.txtDateUpdated = Date
-
End If
-
End If
-
If InStr(1, ctl.Tag, "&") <> 0 Then
-
If inStorage And ctl.Value <> ctl.OldValue Then
-
If MsgBox("WARNING!! Changing Equipment status to In Storage will remove all Logial Equipment Information as well as the Room its assigned to." _
-
& " Are you sure you want to proceed?", vbYesNo) = vbYes Then
-
Me.txtDateUninstalled = Date
-
MsgBox "Uninstalled Date Updated"
-
Me.Dirty = False
-
Call toStorage
-
Else
-
Me.Undo
-
End If
-
ElseIf Not inStorage Then
-
If Nz(Me.cboEquipmentNetworkType, "") = "" _
-
Or Nz(Me.cboSoftwareVersion, "") = "" _
-
Or Nz(Me.txtEquipmentName, "") = "" _
-
Or Nz(Me.txtEquipmentIP, "") = "" _
-
Or Nz(Me.cboCabinetName, "") = "" Then
-
If MsgBox("If Equipment Status is Operational, Logical Information and Physical Location cannot be blank. Do you want to try again?", vbYesNo) = vbYes Then
-
-
Else
-
Me.Undo
-
End If
-
Else
-
Me.txtDateInstalled = Date
-
DoCmd.RunCommand acCmdSaveRecord
-
End If
-
End If
-
End If
-
Next
-
End If
-
-
Me.cboBuildingName.ControlSource = "BuildingFK"
-
Me.cboRoomName.ControlSource = "RoomFK"
-
Else
-
If Nz(Me.cboEquipmentStatus, "") = "" _
-
Or Nz(Me.cboEquipmentModelNum, "") = "" _
-
Or Nz(Me.txtSerialNum, "") = "" Then
-
MsgBox "Equipment Status, Model Number, and Serial Number cannot be empty!", vbOKOnly
-
If Nz(Me.cboEquipmentStatus, "") = "" Then
-
Me.cboEquipmentStatus.SetFocus
-
ElseIf Nz(Me.cboEquipmentModelNum, "") = "" Then
-
Me.cboEquipmentModelNum.SetFocus
-
ElseIf Nz(Me.txtSerialNum, "") = "" Then
-
Me.txtSerialNum.SetFocus
-
End If
-
Exit Sub
-
Else
-
If Me.cboEquipmentStatus.Value = 2 Then
-
addStorage = True
-
ElseIf Me.cboEquipmentStatus.Value = 1 Then
-
addStorage = False
-
End If
-
End If
-
If Not addStorage Then
-
If Nz(Me.cboEquipmentNetworkType, "") = "" _
-
Or Nz(Me.cboSoftwareVersion, "") = "" _
-
Or Nz(Me.txtEquipmentName, "") = "" _
-
Or Nz(Me.txtEquipmentIP, "") = "" _
-
Or Nz(Me.cboCabinetName, "") = "" Then
-
If MsgBox("If Equipment status is ""Operational"" then Logical Equipment Information and Physical Equipment Information " _
-
& " cannot be blank. Would you like to try again?", vbYesNo) = vbYes Then
-
-
Else
-
Call cmdReset_Click
-
End If
-
Else
-
Me.txtDateUninstalled = Date
-
DoCmd.RunCommand acCmdSaveRecord
-
Me.frmSubAddEquipment.Requery
-
Me.DataEntry = False
-
End If
-
Else
-
If Nz(Me.cboEquipmentNetworkType, "") = "" _
-
And Nz(Me.cboSoftwareVersion, "") = "" _
-
And Nz(Me.txtEquipmentName, "") = "" _
-
And Nz(Me.txtEquipmentIP, "") = "" _
-
And Nz(Me.cboCabinetName, "") = "" Then
-
Me.txtDateUninstalled = Date
-
DoCmd.RunCommand acCmdSaveRecord
-
Me.frmSubAddEquipment.Requery
-
Me.DataEntry = False
-
Else
-
If MsgBox("If Equipment status is ""In Storage"" then Logical Equipment Information and Physical Equipment Information " _
-
& " must be blank. Would you like to try again?", vbYesNo) = vbYes Then
-
-
Else
-
Call cmdReset_Click
-
End If
-
End If
-
End If
-
End If
-
End Sub
I do have one other problem. I'll do my best to explain it and I hope its not too confusing.
I bolded the section of my code that isn't exactly working as it should.
I am comparing the value of that combo box to its old value because I want it to be so that if the user changed cboEquipmentStatus from Operational to "In Storage" it will give them a warning and then remove all logical information (hostname, ip address, etc).
That works great, however it is flawed in that if cboEquipmentStatus was already set to "In Storage" and it was not changed, it will allow users to add logical switch information.
I could simply have "if inStorage Then..." But that would bring up a warning time every time someone was editing a record which was In Storage, and thats a pain.
Thank you for your help.
What I would do in this case is create a function that disables all the pertinent fields if the EquipmentStatus is 2 and Enables the Fields if the EquipmentStatus is something else. I would then call this function from the OnCurrent Event of the Form and OnChange Event of EquipmentStatus. I would also Clear Out of the other Fields to the OnChange of the EquipmentStatus.
Then you wont need to validate the Data on Save, it will just be right.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Filips Benoit |
last post by:
Hi,
TBL_CONTACT_PERSON
CNTP_ID (auto)
CNTP_LAST_NAME (required = yes)
CNTP_FUNCTION (required = no)
CNTP_..... (all required = no)
FRM_CONTACT_PERSON_ADD_NEW
Property DATA ENTRY = YES
|
by: edworboys |
last post by:
I have a form (Prospect) with a subform (Document).
The result I am looking for is this:
The user selects a prospect which is made up of Prospect Name, Country,
Company and Prospect Type. They...
|
by: Joe Cajon via AccessMonster.com |
last post by:
In a multiuser access/jet database, I need to provide multiple instance
order entry form/continuous subform. I have been looking for best
practice, but there seem to be competing ideas. Want to...
|
by: John |
last post by:
Hi
I am using the following code to save the changes to a form's data in the
form's Before Update event;
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.OldValue <>...
|
by: ye2127 |
last post by:
Can someone please give me advice on how to do the following in a form?
In my form I have a have the user enter a 1 or a 2 in a box for the first record.
I would like to know how I can make...
|
by: bosmatthews |
last post by:
I have a main form with a subform and a second subform nested to the first subform. The data entry property for all three forms (main, subform and sub-subform) is set to "yes" because I am intending...
|
by: GarthRodgers |
last post by:
Hey
I'm designing a booking system and on my booking form I have an ActiveX Calendar control. The user selects the date on the calendar, which is then transferred into a text box, whose control...
|
by: ilikebirds |
last post by:
This may be a dream.
However I was wondering if the following scenario were possible within an Access 2003 Form.
If I have to fields and , both of which are have limited field sizes of 4, Would...
|
by: rameshch45 |
last post by:
I am developing a JSP/Struts application and there are two features where the user need to enter information about the form in his HTML page (which is not accessible to my application). He need to...
|
by: angeliki |
last post by:
I have an access database with a main form and four sub forms. I can enter data through the forms, and this is fed through to the underlying tables. However, when i close the form and re-open it, I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |