• help with simple IF…Then (A2002)

    Author
    Topic
    #394584

    This will be my first IF…Then.

    What I want to set up is, if control1 is null, give it the value of control2. Both controls on the same form. Here’s what I came up with on the OnCurrent event for the form:

    If [Control1] = Null Then
    [Control2] = [Control1]
    End IF

    How do I make this work?

    elizabeth

    Viewing 1 reply thread
    Author
    Replies
    • #724416

      To check is something is null in code, you can use the IsNull function:

      If IsNull([Control1]) Then
      ‘ Make value of Control1 equal to that of Control2
      [Control1] = [Control2]
      End If

      Note the order of the assignment statement. A shorter alternative is to replace the above code by

      [Control1] = Nz([Control1], [Control2])

      The Nz function returns the first argument, but if that is null, it returns the second argument.

      Is Control1 bound to a field in the record source of the form? What should happen if the user updates Control2? Should the value of Control1 be updated too?

      • #724418

        Thanks for your help. Re your question, it’s one way only. Like First Name and Badge Name. Usually it’s the same, Wendy and Wendy, but it could be William and Bill. I’m doing this after the fact. I didn’t anticipate needing the second field when I originally set up the table and form.

        e

        • #724420

          Hi Elizabeth,

          I would put the code in the BeforeUpdate event of the form. Using the BeforeUpdate event ensures that when the user creates a new record and leaves Badge Name empty, it will be filled when the user leaves the record.

          I would also create an update query to populate the Badge Name field for existing records.

          • #724432

            (Edited by ppem on 05-Oct-03 00:07. )

            I was thinking of setting the default value of Badge Name to First Name. Is the Before Update a better bet than the default value?

            I did try putting =[FirstName] in the default value, but that’s obviously not it.

            e

            • #724474

              The Default Value property is applied when you create a new record, before you as user have filled in anything. So the First Name field is still empty; therefore Badge Name remains empty too.

              The Before Update event occurs after you have entered data in the record or modified existing data, so it is better suited for what you want.

            • #725315

              Thanks. Really appreciate your expertise.

              E

            • #725316

              Thanks. Really appreciate your expertise.

              E

            • #724475

              The Default Value property is applied when you create a new record, before you as user have filled in anything. So the First Name field is still empty; therefore Badge Name remains empty too.

              The Before Update event occurs after you have entered data in the record or modified existing data, so it is better suited for what you want.

          • #724433

            (Edited by ppem on 05-Oct-03 00:07. )

            I was thinking of setting the default value of Badge Name to First Name. Is the Before Update a better bet than the default value?

            I did try putting =[FirstName] in the default value, but that’s obviously not it.

            e

          • #746238

            I would also create an update query to populate the Badge Name field for existing records.

            Hans: I’m trying to do something similar, but I’m having trouble writing an update query to populate my existing records. I’ve written update queries before, where I’m updating a field in one table with the data in a field from another table. In this case, I’m working with just the one table. My table, tblStudents, has fields for FirstName and Nickname. In almost all cases, Nickname will equal FirstName. Here’s what I’ve done so far:

            I’ve created a new query with the tblStudents, and I’ve added FirstName and Nickname to the design grid. Then I made the query into an Update query and keyed in the following in the Update To: line under Nickname:

            If IsNull ([Nickname]), [Nickname] = ([tblStudentsCopy]. [FirstName])

            I’m just taking a shot at how to write this, but so far I’m getting error messages about operators and operands…. bagged Clearly, I need some professional help!

            Also, I tried following the advice about code in the Before Update event, but my efforts haven’t worked. After I wrote the event procedure, I tried entering a new bogus record and left Nickname field blank. To my dismay, the form failed to populate the Nickname field with the FirstName. Here’s my code–anything wrong with it?

            Private Sub Nickname_BeforeUpdate(Cancel As Integer)

            If IsNull([Nickname]) Then
            ‘Make Nickname equal the First Name
            [Nickname] = [FirstName]
            End If
            End Sub

            Thanks!

            • #746336

              You can’t put a VBA statement in a query.

              If I understand you correctly, you want to set Nickname to FirstName, but only if it hasn’t been filled in yet.
              – Create a query based on tblStudents.
              – Add ONLY the Nickname field to the design grid.
              – Enter Is Null in the Criteria: line. This makes the query use only those records whose Nickname is empty.
              – Change the query to an Update query.
              – Enter [FirstName] in the Update to: line
              – Execute the query.

            • #746656

              Hans: You understood my intentions perfectly, and now I’ve got the query problem fixed. Thanks again!

              There’s still the problem with the Event Procedure and the form. I’ve looked again and again at my code, and my amateur’s eyes can’t see any problem with it. Nonetheless, when I enter a bogus student and leave the Nickname field empty, the form does not display the FirstName in the Nickname field. What could be the problem?

            • #746668

              Put the code in the Form_BeforeUpdate event instead of in the NickName_BeforeUpdate event. NickName_BeforeUpdate only occurs if the user changes NickName, but that is precisely what (s)he didn’t do.

            • #746690

              OK…I put the code into the Form_BeforeUpdate event, and still the form refuses to display FirstName in the Nickname field when Nickname is null. I’ve tried both versions of the code (the long version and the shorter version using the Nz function) without success.

              The form gets it data straight from the tblStudents table. I’d started out using a query as the datasource, and I suspected there was something in my query that was causing this behavior. So I switched the datasource to the table, but the problem persists.

            • #746698

              Lucas,

              It is important to keep in mind when events occur.

              • The Before Update and After Update events of a control occur only if the value of the control has been changed by the user.
                For a text box, the events occur when the user moves to another control after changing the text.
                For a check box, whenever the user clicks the check box.
              • The Before Update and After Update events of the form occur only if the record as a whole has been changed by the user, when the user moves to another record or closes the form.
                [/list]Neither of these events will modify an existing record if the user looks at it without modifying anything.

                You should run the update query once. This will copy the first name to the nickname field for all records in which nickname is empty. After that, the Before Update event of the form will ensure that the nickname field will be kept up-to-date.

            • #746706

              Thank you, Hans. Here’s what I did a while ago (if memory serves): First, I ran the update query as you recommended. That did in fact plug the first name into the Nickname field wherever Nickname was empty. Now all 600-plus records had something in the Nickname field. Next I entered a bogus student record, but I left the Nickname field blank. I expected to see the form pick up the FirstName and fill the void in Nickname, but that didn’t happen. It didn’t happen after I closed and reopened the form, nor did it happen after I ran Compact & Repair. I remain confused….

            • #746710

              Have you put the code in the Before Update event of the form now? Does Nickname still remain empty with this code in place?

            • #746718

              Yes. Here’s the code from the VBE:

              Private Sub Form_BeforeUpdate(Cancel As Integer)

              If IsNull([Nickname]) Then
              ‘Make Nickname equal the First Name
              [Nickname] = [FirstName]
              End If

              End Sub

            • #746744

              Perhaps the event code has become disconnected from the event.

              • Open the form in design view.
              • Activate the Event tab of the Properties window.
              • If the Before Update event doesn’t show Event Procedure, select that from the dropdown list.
              • Click the Builder button (the three dots … to the right.)
              • Verify that you see the correct code.
              • Select Debug | Compile
                [/list]Does this help?
            • #746746

              In a word…no. frown

            • #746754

              Then I don’t understand. Could you post a stripped-down copy of the database? Remove everything except the problem form, plus the tables and queries needed for it. You can remove all records from the student table. Compact, then zip the database.

            • #746770

              Here you go. Thanks for taking the time…. salute

            • #746784

              Lucas,

              Databases (and computers in general) only do what you tell them to do, they don’t guess your wishes and fulfill them by magic.

              You have created a Before Update event procedure for the frmStudentModify form, and it works there as intended when you modify anything in an existing record.

              You have NOT created a Before Update event procedure for the fqdfNewStudent form, so nothing happens if you leave the nickname blank in a new record. You can’t expect Access to apply the event procedure for one form in another form.

              So what you have to do is create a Before Update event procedure for fqdfNewStudent; you can copy it from frmStudentModify.

            • #746794

              Oh…! blush

              I’ll do that and let you know how it goes! Thanx!!

            • #746804

              yep Yep…that did it! Thank you, Hans!

            • #746805

              yep Yep…that did it! Thank you, Hans!

            • #746795

              Oh…! blush

              I’ll do that and let you know how it goes! Thanx!!

            • #746824

              Hans, you’ve fixed my problem with the Nickname! Just one more question about this same form (although a slightly different topic).

              You’ve seen my two forms (frmStudentModify and fqdfNewStudent). When I add a new student and close the new student form, naturally I’d like that new record to show up in the frmStudentModify form. But it doesn’t. I’ve used code that you supplied to fix similar conditions in another application, but I’m not sure where to put the code. My semi-educated hunch is that I should put it in the on-click event of the command button on the new student form (“Exit and return to Modify Student form”). I went back and reviewed some of my earlier posts and your replies, and I rewrote the code for the on-click event. Here’s how it looks now:

              Private Sub Close_this_form_Click()
              On Error GoTo Err_Close_this_form_Click

              If Me.Dirty Then
              RunCommand acCmdSaveRecord
              End If

              DoCmd.Close

              Exit_Close_this_form_Click:
              Exit Sub

              Err_Close_this_form_Click:
              MsgBox Err.Description
              Resume Exit_Close_this_form_Click

              End Sub

              The good news is that the button still works as before, but the new record doesn’t appear in the “home form” until I close and reopen the form.

              Where have I gone astray?

            • #746964

              Your addition does no harm, but it is superfluous: the record will be saved automatically when the form closes. You might as well take it out again.

              Again, one form won’t react automatically to what the other does. fqdfNewStudent will have to let frmStudentModify know which PID has been added, and frmStudentModify must react to this. You can pass this information via a global variable or via a control. In the following, I have used a global variable.

              In a general module:

              Public varNewPID As Variant

              In the Close_this_form_Click procedure of fqdfNewStudent, set the value of the variable, above DoCmd.Close:

              varNewPID = Me.PID

              In the cmdAddNewStudent_Click procedure of frmStudentModify, clear the variable, then open the other form as a dialog form (to prevent the user from clicking back to the main form). When the user has closed this form, requery the form, check if the variable has been set, and if so, move to the new PID.

              Private Sub cmdAddNewStudent_Click()
              Dim stDocName As String
              Dim stLinkCriteria As String
              Dim rs As Object

              On Error GoTo Err_cmdAddNewStudent_Click

              varNewPID = Null
              stDocName = “fqdfNewStudent”
              DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog

              If Not IsNull(varNewPID) Then
              ‘ Read the records anew
              Me.Requery
              ‘ Find the record that matches the control.
              Set rs = Me.Recordset.Clone
              rs.FindFirst “[PID] = ” & varNewPID
              If Not rs.EOF Then Me.Bookmark = rs.Bookmark
              Set rs = Nothing
              End If

              Exit_cmdAddNewStudent_Click:
              Exit Sub

              Err_cmdAddNewStudent_Click:
              MsgBox Err.Description
              Resume Exit_cmdAddNewStudent_Click
              End Sub

            • #747248

              Good morning, Hans! (Well, it’s morning here on the East Coast of the US, anyway!) Thanks again for all the help and information!

              I’m sure you can understand why an amateur like myself would expect those two forms to work with each other. After all, they’re both feeding to and from the same table, so why shouldn’t they automatically what each is doing? But you’ve helped me to understand that’s not the case, and I’ll proceed from there.

              I’ve followed your advice re: making Option Explicit appear in my modules. If I understand you correctly, my checking that little box willl have no effect on any existing modules. As I view the code window in the VBE just now, I see “Option Compare Database” at the top. Then there’s a line, and the code modules appear below the line, and each module has a line to separate it from the one below it. So if I were to edit a module, I’d key in Option Explicit at the beginning of the module as the first line…like this:

              Option Explicit
              Private Sub Form_BeforeUpdate(Cancel As Integer)
              etc, etc.

              I just want to make sure I get this right…. grin Thanks again, hero!

            • #747252

              You’re correct, setting “Require variable declaration” only affects new modules, it won’t add Option explicit to existing modules. you’ll have to do that yourself.

              It doesn’t matter which of the two Option lines at the top of the module comes first. This is correct:

              Option Compare Database
              Option Explicit

              Private Sub …

              and this is correct too:

              Option Explicit
              Option Compare Database

              Private Sub…

              but this isn’t (you’ll get an error message):

              Private Sub …

              End Sub

              Option Explicit
              Option Compare Database

            • #747253

              You’re correct, setting “Require variable declaration” only affects new modules, it won’t add Option explicit to existing modules. you’ll have to do that yourself.

              It doesn’t matter which of the two Option lines at the top of the module comes first. This is correct:

              Option Compare Database
              Option Explicit

              Private Sub …

              and this is correct too:

              Option Explicit
              Option Compare Database

              Private Sub…

              but this isn’t (you’ll get an error message):

              Private Sub …

              End Sub

              Option Explicit
              Option Compare Database

            • #747249

              Good morning, Hans! (Well, it’s morning here on the East Coast of the US, anyway!) Thanks again for all the help and information!

              I’m sure you can understand why an amateur like myself would expect those two forms to work with each other. After all, they’re both feeding to and from the same table, so why shouldn’t they automatically what each is doing? But you’ve helped me to understand that’s not the case, and I’ll proceed from there.

              I’ve followed your advice re: making Option Explicit appear in my modules. If I understand you correctly, my checking that little box willl have no effect on any existing modules. As I view the code window in the VBE just now, I see “Option Compare Database” at the top. Then there’s a line, and the code modules appear below the line, and each module has a line to separate it from the one below it. So if I were to edit a module, I’d key in Option Explicit at the beginning of the module as the first line…like this:

              Option Explicit
              Private Sub Form_BeforeUpdate(Cancel As Integer)
              etc, etc.

              I just want to make sure I get this right…. grin Thanks again, hero!

            • #746965

              Your addition does no harm, but it is superfluous: the record will be saved automatically when the form closes. You might as well take it out again.

              Again, one form won’t react automatically to what the other does. fqdfNewStudent will have to let frmStudentModify know which PID has been added, and frmStudentModify must react to this. You can pass this information via a global variable or via a control. In the following, I have used a global variable.

              In a general module:

              Public varNewPID As Variant

              In the Close_this_form_Click procedure of fqdfNewStudent, set the value of the variable, above DoCmd.Close:

              varNewPID = Me.PID

              In the cmdAddNewStudent_Click procedure of frmStudentModify, clear the variable, then open the other form as a dialog form (to prevent the user from clicking back to the main form). When the user has closed this form, requery the form, check if the variable has been set, and if so, move to the new PID.

              Private Sub cmdAddNewStudent_Click()
              Dim stDocName As String
              Dim stLinkCriteria As String
              Dim rs As Object

              On Error GoTo Err_cmdAddNewStudent_Click

              varNewPID = Null
              stDocName = “fqdfNewStudent”
              DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog

              If Not IsNull(varNewPID) Then
              ‘ Read the records anew
              Me.Requery
              ‘ Find the record that matches the control.
              Set rs = Me.Recordset.Clone
              rs.FindFirst “[PID] = ” & varNewPID
              If Not rs.EOF Then Me.Bookmark = rs.Bookmark
              Set rs = Nothing
              End If

              Exit_cmdAddNewStudent_Click:
              Exit Sub

              Err_cmdAddNewStudent_Click:
              MsgBox Err.Description
              Resume Exit_cmdAddNewStudent_Click
              End Sub

            • #746966

              Lucas,

              I notice that your modules don’t contain Option Explicit. I’m amazed, since this comes up frequently in this forum, and we always recommend to use this.

              I strongly recommend that you do the following things:
              – In the Visual Basic Editor, select Tools | Options…, and tick Require Variable Declaration. This will add Option Explicit at or near the top of new modules you create.
              – Whenever you edit a module, check if Option Explicit is at or near the top of the module. If not, insert it as the first line.

              Option Explicit requires that you declare all variables you use. This may seem a nuisance at first, but it will prevent hard-to-track errors. If you don’t have Option Explicit, you create a variable by using its name. VBA won’t spot the following error:

              Value1 = 33
              Value2 = 37

              Value3 = Value1 + Valeu2

              Since Valeu2 was not used before, VBA will create it, with a default value of 0. So Value3 will be 33 + 0 = 33, instead of 33 + 37 = 70, as intended.

              If you have Option Explicit, you must declare the variables you use:

              Dim Value1 As Long
              Dim Value2 As Long
              Dim Value3 As Long

              Value1 = 33
              Value2 = 37

              Value3 = Value1 + Valeu2

              You’ll get a compile error: variable not defined, with Valeu2 highlighted. This alerts you to a typo that might otherwise have gone unnoticed.

            • #746967

              Lucas,

              I notice that your modules don’t contain Option Explicit. I’m amazed, since this comes up frequently in this forum, and we always recommend to use this.

              I strongly recommend that you do the following things:
              – In the Visual Basic Editor, select Tools | Options…, and tick Require Variable Declaration. This will add Option Explicit at or near the top of new modules you create.
              – Whenever you edit a module, check if Option Explicit is at or near the top of the module. If not, insert it as the first line.

              Option Explicit requires that you declare all variables you use. This may seem a nuisance at first, but it will prevent hard-to-track errors. If you don’t have Option Explicit, you create a variable by using its name. VBA won’t spot the following error:

              Value1 = 33
              Value2 = 37

              Value3 = Value1 + Valeu2

              Since Valeu2 was not used before, VBA will create it, with a default value of 0. So Value3 will be 33 + 0 = 33, instead of 33 + 37 = 70, as intended.

              If you have Option Explicit, you must declare the variables you use:

              Dim Value1 As Long
              Dim Value2 As Long
              Dim Value3 As Long

              Value1 = 33
              Value2 = 37

              Value3 = Value1 + Valeu2

              You’ll get a compile error: variable not defined, with Valeu2 highlighted. This alerts you to a typo that might otherwise have gone unnoticed.

            • #746825

              Hans, you’ve fixed my problem with the Nickname! Just one more question about this same form (although a slightly different topic).

              You’ve seen my two forms (frmStudentModify and fqdfNewStudent). When I add a new student and close the new student form, naturally I’d like that new record to show up in the frmStudentModify form. But it doesn’t. I’ve used code that you supplied to fix similar conditions in another application, but I’m not sure where to put the code. My semi-educated hunch is that I should put it in the on-click event of the command button on the new student form (“Exit and return to Modify Student form”). I went back and reviewed some of my earlier posts and your replies, and I rewrote the code for the on-click event. Here’s how it looks now:

              Private Sub Close_this_form_Click()
              On Error GoTo Err_Close_this_form_Click

              If Me.Dirty Then
              RunCommand acCmdSaveRecord
              End If

              DoCmd.Close

              Exit_Close_this_form_Click:
              Exit Sub

              Err_Close_this_form_Click:
              MsgBox Err.Description
              Resume Exit_Close_this_form_Click

              End Sub

              The good news is that the button still works as before, but the new record doesn’t appear in the “home form” until I close and reopen the form.

              Where have I gone astray?

            • #746785

              Lucas,

              Databases (and computers in general) only do what you tell them to do, they don’t guess your wishes and fulfill them by magic.

              You have created a Before Update event procedure for the frmStudentModify form, and it works there as intended when you modify anything in an existing record.

              You have NOT created a Before Update event procedure for the fqdfNewStudent form, so nothing happens if you leave the nickname blank in a new record. You can’t expect Access to apply the event procedure for one form in another form.

              So what you have to do is create a Before Update event procedure for fqdfNewStudent; you can copy it from frmStudentModify.

            • #746771

              Here you go. Thanks for taking the time…. salute

            • #746755

              Then I don’t understand. Could you post a stripped-down copy of the database? Remove everything except the problem form, plus the tables and queries needed for it. You can remove all records from the student table. Compact, then zip the database.

            • #746747

              In a word…no. frown

            • #746745

              Perhaps the event code has become disconnected from the event.

              • Open the form in design view.
              • Activate the Event tab of the Properties window.
              • If the Before Update event doesn’t show Event Procedure, select that from the dropdown list.
              • Click the Builder button (the three dots … to the right.)
              • Verify that you see the correct code.
              • Select Debug | Compile
                [/list]Does this help?
            • #746719

              Yes. Here’s the code from the VBE:

              Private Sub Form_BeforeUpdate(Cancel As Integer)

              If IsNull([Nickname]) Then
              ‘Make Nickname equal the First Name
              [Nickname] = [FirstName]
              End If

              End Sub

            • #746711

              Have you put the code in the Before Update event of the form now? Does Nickname still remain empty with this code in place?

            • #746707

              Thank you, Hans. Here’s what I did a while ago (if memory serves): First, I ran the update query as you recommended. That did in fact plug the first name into the Nickname field wherever Nickname was empty. Now all 600-plus records had something in the Nickname field. Next I entered a bogus student record, but I left the Nickname field blank. I expected to see the form pick up the FirstName and fill the void in Nickname, but that didn’t happen. It didn’t happen after I closed and reopened the form, nor did it happen after I ran Compact & Repair. I remain confused….

            • #746699

              Lucas,

              It is important to keep in mind when events occur.

              • The Before Update and After Update events of a control occur only if the value of the control has been changed by the user.
                For a text box, the events occur when the user moves to another control after changing the text.
                For a check box, whenever the user clicks the check box.
              • The Before Update and After Update events of the form occur only if the record as a whole has been changed by the user, when the user moves to another record or closes the form.
                [/list]Neither of these events will modify an existing record if the user looks at it without modifying anything.

                You should run the update query once. This will copy the first name to the nickname field for all records in which nickname is empty. After that, the Before Update event of the form will ensure that the nickname field will be kept up-to-date.

            • #746691

              OK…I put the code into the Form_BeforeUpdate event, and still the form refuses to display FirstName in the Nickname field when Nickname is null. I’ve tried both versions of the code (the long version and the shorter version using the Nz function) without success.

              The form gets it data straight from the tblStudents table. I’d started out using a query as the datasource, and I suspected there was something in my query that was causing this behavior. So I switched the datasource to the table, but the problem persists.

            • #746669

              Put the code in the Form_BeforeUpdate event instead of in the NickName_BeforeUpdate event. NickName_BeforeUpdate only occurs if the user changes NickName, but that is precisely what (s)he didn’t do.

            • #746700

              Lucas
              I think you’ll find the code should be applied to the event procedure of [FirstName] not [Nickname]. Nickname never gets updated if it remains null.
              Peter

            • #746701

              Lucas
              I think you’ll find the code should be applied to the event procedure of [FirstName] not [Nickname]. Nickname never gets updated if it remains null.
              Peter

            • #746657

              Hans: You understood my intentions perfectly, and now I’ve got the query problem fixed. Thanks again!

              There’s still the problem with the Event Procedure and the form. I’ve looked again and again at my code, and my amateur’s eyes can’t see any problem with it. Nonetheless, when I enter a bogus student and leave the Nickname field empty, the form does not display the FirstName in the Nickname field. What could be the problem?

            • #746337

              You can’t put a VBA statement in a query.

              If I understand you correctly, you want to set Nickname to FirstName, but only if it hasn’t been filled in yet.
              – Create a query based on tblStudents.
              – Add ONLY the Nickname field to the design grid.
              – Enter Is Null in the Criteria: line. This makes the query use only those records whose Nickname is empty.
              – Change the query to an Update query.
              – Enter [FirstName] in the Update to: line
              – Execute the query.

          • #746239

            I would also create an update query to populate the Badge Name field for existing records.

            Hans: I’m trying to do something similar, but I’m having trouble writing an update query to populate my existing records. I’ve written update queries before, where I’m updating a field in one table with the data in a field from another table. In this case, I’m working with just the one table. My table, tblStudents, has fields for FirstName and Nickname. In almost all cases, Nickname will equal FirstName. Here’s what I’ve done so far:

            I’ve created a new query with the tblStudents, and I’ve added FirstName and Nickname to the design grid. Then I made the query into an Update query and keyed in the following in the Update To: line under Nickname:

            If IsNull ([Nickname]), [Nickname] = ([tblStudentsCopy]. [FirstName])

            I’m just taking a shot at how to write this, but so far I’m getting error messages about operators and operands…. bagged Clearly, I need some professional help!

            Also, I tried following the advice about code in the Before Update event, but my efforts haven’t worked. After I wrote the event procedure, I tried entering a new bogus record and left Nickname field blank. To my dismay, the form failed to populate the Nickname field with the FirstName. Here’s my code–anything wrong with it?

            Private Sub Nickname_BeforeUpdate(Cancel As Integer)

            If IsNull([Nickname]) Then
            ‘Make Nickname equal the First Name
            [Nickname] = [FirstName]
            End If
            End Sub

            Thanks!

        • #724421

          Hi Elizabeth,

          I would put the code in the BeforeUpdate event of the form. Using the BeforeUpdate event ensures that when the user creates a new record and leaves Badge Name empty, it will be filled when the user leaves the record.

          I would also create an update query to populate the Badge Name field for existing records.

      • #724419

        Thanks for your help. Re your question, it’s one way only. Like First Name and Badge Name. Usually it’s the same, Wendy and Wendy, but it could be William and Bill. I’m doing this after the fact. I didn’t anticipate needing the second field when I originally set up the table and form.

        e

    • #724417

      To check is something is null in code, you can use the IsNull function:

      If IsNull([Control1]) Then
      ‘ Make value of Control1 equal to that of Control2
      [Control1] = [Control2]
      End If

      Note the order of the assignment statement. A shorter alternative is to replace the above code by

      [Control1] = Nz([Control1], [Control2])

      The Nz function returns the first argument, but if that is null, it returns the second argument.

      Is Control1 bound to a field in the record source of the form? What should happen if the user updates Control2? Should the value of Control1 be updated too?

    Viewing 1 reply thread
    Reply To: help with simple IF…Then (A2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: