473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

If statement for form data entry property

70 64KB
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2.          Dim ctl As Control
  3.          Dim myForm As Form
  4.          Set myForm = Me.Form
  5.          Dim inStorage As Boolean
  6.          inStorage = False
  7.          inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
  8.          inStorage = inStorage Or Me.cboEquipmentStatus.Value = 3
  9.          If Me.Form.DataEntry = False Then
  10.              If Me.Dirty Then
  11.                  For Each ctl In myForm
  12.                       If InStr(1, ctl.Tag, "*") <> 0 Then
  13.                           If ctl.Value <> ctl.OldValue Then
  14.                               Me.txtDateUpdated = Date
  15.                           End If
  16.                       End If
  17.                       If InStr(1, ctl.Tag, "&") <> 0 Then
  18.                           If inStorage And ctl.Value <> ctl.OldValue Then
  19.                               If MsgBox("WARNING!! Changing Equipment status to In Storage will remove all Logial Equipment Information as well as the Room its assigned to." _
  20.                               & " Are you sure you want to proceed?", vbYesNo) = vbYes Then
  21.                                   Me.txtDateUninstalled = Date
  22.                                   MsgBox "Uninstalled Date Updated"
  23.                                   Me.Dirty = False
  24.                                   Call toStorage
  25.                               Else
  26.                                   Me.Undo
  27.                               End If
  28.                           ElseIf Not inStorage Then
  29.                               If IsNull(Me.txtEquipmentName.Value) Or (Me.txtEquipmentName.Value) = "" _
  30.                               Or IsNull(Me.txtEquipmentIP.Value) Or (Me.txtEquipmentIP.Value) = "" _
  31.                               Or IsNull(Me.cboSoftwareVersion.Value) Or (Me.cboSoftwareVersion.Value) = "" _
  32.                               Or IsNull(Me.cboCabinetName.Value) Or (Me.cboCabinetName.Value) = "" Then
  33.                                   If MsgBox("If Equipment Status is Operational, Logical Information and Physical Location cannot be blank. Do you want to try again?", vbYesNo) = vbYes Then
  34.  
  35.                                   Else
  36.                                       Me.Undo
  37.                                   End If
  38.                               Else
  39.                                   Me.txtDateInstalled = Date
  40.                               End If
  41.                           End If
  42.                       End If
  43.                  Next
  44.              End If
  45.                  DoCmd.RunCommand acCmdSaveRecord
  46.                  Me.cboBuildingName.ControlSource ="BuildingFK"
  47.                  Me.cboRoomName.ControlSource = "RoomFK"
  48.         Else
  49.             DoCmd.RunCommand acCmdSaveRecord
  50.             Me.frmSubAddEquipment.Requery
  51.         End If
  52. End Sub
  53.  
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?
Nov 18 '15 #1
6 1140
jforbes
1,107 Expert 1GB
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?
Nov 18 '15 #2
ittechguy
70 64KB
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?
Nov 18 '15 #3
jforbes
1,107 Expert 1GB
I sorta understand.

I think what is possibly messing you up is that
Expand|Select|Wrap|Line Numbers
  1. Me.Dirty = False 
will force a save.
Nov 18 '15 #4
ittechguy
70 64KB
I figured it out. Thanks for your help. Now its mostly working and code is maybe 95% complete.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2.          Dim ctl As Control
  3.          Dim myForm As Form
  4.          Set myForm = Me.Form
  5.          Dim inStorage As Boolean
  6.          Dim addStorage As Boolean
  7.          If Not IsNull(Me.cboEquipmentStatus.Value) Or Not (Me.cboEquipmentStatus.Value) = "" Then
  8.              inStorage = False
  9.              inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
  10.          End If
  11.  
  12.          If Me.Form.DataEntry = False Then
  13.              If Me.Dirty Then
  14.                  For Each ctl In myForm
  15.                       If InStr(1, ctl.Tag, "*") <> 0 Then
  16.                           If ctl.Value <> ctl.OldValue Then
  17.                               Me.txtDateUpdated = Date
  18.                           End If
  19.                       End If
  20.                       If InStr(1, ctl.Tag, "&") <> 0 Then
  21.                           If inStorage And ctl.Value <> ctl.OldValue Then
  22.                               If MsgBox("WARNING!! Changing Equipment status to In Storage will remove all Logial Equipment Information as well as the Room its assigned to." _
  23.                               & " Are you sure you want to proceed?", vbYesNo) = vbYes Then
  24.                                   Me.txtDateUninstalled = Date
  25.                                   MsgBox "Uninstalled Date Updated"
  26.                                   Me.Dirty = False
  27.                                   Call toStorage
  28.                               Else
  29.                                   Me.Undo
  30.                               End If
  31.                           ElseIf Not inStorage Then
  32.                               If Nz(Me.cboEquipmentNetworkType, "") = "" _
  33.                               Or Nz(Me.cboSoftwareVersion, "") = "" _
  34.                               Or Nz(Me.txtEquipmentName, "") = "" _
  35.                               Or Nz(Me.txtEquipmentIP, "") = "" _
  36.                               Or Nz(Me.cboCabinetName, "") = "" Then
  37.                                   If MsgBox("If Equipment Status is Operational, Logical Information and Physical Location cannot be blank. Do you want to try again?", vbYesNo) = vbYes Then
  38.  
  39.                                   Else
  40.                                       Me.Undo
  41.                                   End If
  42.                               Else
  43.                                   Me.txtDateInstalled = Date
  44.                                   DoCmd.RunCommand acCmdSaveRecord
  45.                               End If
  46.                           End If
  47.                       End If
  48.                  Next
  49.              End If
  50.  
  51.                  Me.cboBuildingName.ControlSource = "BuildingFK"
  52.                  Me.cboRoomName.ControlSource = "RoomFK"
  53.         Else
  54.         If Nz(Me.cboEquipmentStatus, "") = "" _
  55.         Or Nz(Me.cboEquipmentModelNum, "") = "" _
  56.         Or Nz(Me.txtSerialNum, "") = "" Then
  57.             MsgBox "Equipment Status, Model Number, and Serial Number cannot be empty!", vbOKOnly
  58.                 If Nz(Me.cboEquipmentStatus, "") = "" Then
  59.                     Me.cboEquipmentStatus.SetFocus
  60.                 ElseIf Nz(Me.cboEquipmentModelNum, "") = "" Then
  61.                     Me.cboEquipmentModelNum.SetFocus
  62.                 ElseIf Nz(Me.txtSerialNum, "") = "" Then
  63.                     Me.txtSerialNum.SetFocus
  64.                 End If
  65.                     Exit Sub
  66.         Else
  67.             If Me.cboEquipmentStatus.Value = 2 Then
  68.                 addStorage = True
  69.             ElseIf Me.cboEquipmentStatus.Value = 1 Then
  70.                 addStorage = False
  71.             End If
  72.         End If
  73.         If Not addStorage Then
  74.                 If Nz(Me.cboEquipmentNetworkType, "") = "" _
  75.                 Or Nz(Me.cboSoftwareVersion, "") = "" _
  76.                 Or Nz(Me.txtEquipmentName, "") = "" _
  77.                 Or Nz(Me.txtEquipmentIP, "") = "" _
  78.                 Or Nz(Me.cboCabinetName, "") = "" Then
  79.                      If MsgBox("If Equipment status is ""Operational"" then Logical Equipment Information and Physical Equipment Information " _
  80.                      & " cannot be blank. Would you like to try again?", vbYesNo) = vbYes Then
  81.  
  82.                      Else
  83.                          Call cmdReset_Click
  84.                      End If
  85.                  Else
  86.                      Me.txtDateUninstalled = Date
  87.                      DoCmd.RunCommand acCmdSaveRecord
  88.                      Me.frmSubAddEquipment.Requery
  89.                      Me.DataEntry = False
  90.                  End If
  91.             Else
  92.                 If Nz(Me.cboEquipmentNetworkType, "") = "" _
  93.                 And Nz(Me.cboSoftwareVersion, "") = "" _
  94.                 And Nz(Me.txtEquipmentName, "") = "" _
  95.                 And Nz(Me.txtEquipmentIP, "") = "" _
  96.                 And Nz(Me.cboCabinetName, "") = "" Then
  97.                     Me.txtDateUninstalled = Date
  98.                     DoCmd.RunCommand acCmdSaveRecord
  99.                     Me.frmSubAddEquipment.Requery
  100.                     Me.DataEntry = False
  101.                 Else
  102.                     If MsgBox("If Equipment status is ""In Storage"" then Logical Equipment Information and Physical Equipment Information " _
  103.                      & " must be blank. Would you like to try again?", vbYesNo) = vbYes Then
  104.  
  105.                      Else
  106.                          Call cmdReset_Click
  107.                      End If
  108.                 End If
  109.             End If
  110.         End If
  111. 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.
Nov 20 '15 #5
jforbes
1,107 Expert 1GB
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.
Nov 20 '15 #6
ittechguy
70 64KB
Thanks for the help. Its still not solved, not sure what I'm doing wrong.

I have tried using AfterUpdate as well.

I have a new thread here: https://bytes.com/topic/access/answe...ox#post3798647
Nov 20 '15 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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
1
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...
3
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...
3
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 <>...
6
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...
3
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...
4
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...
4
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...
7
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...
9
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...
0
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,...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.