473,386 Members | 1,715 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.

Call Tracker MS Access Template

I'm working from MS Access "Call Tracker" template and I need some help.

What I'm Using:
MICROSOFT OFFICE 365
ACCESS 2016 MSO (16.0.6965.2053) 32-bit

On the form "Call Details" I need to add two extra fields (4 total but the other two are simple text fileds): Under "Called In By" I need to add "Called In By Phone" and "Bill To" both of which are stored in both "Customers" and "Customers Extended" tables - [Customers Extended] is the SQL for the combo box source. The source for the form is [Calls].

These three fields: [Called In By], [Called In by Phone], and [Bill To] I need to operate as one - meaning when a caller is selected the other two fields are populated automatically.

I did manage to get the two boxes pre-filled using the code below but it does not use any IF logic. I'm not sure where to put the IF logic - here in the VBA or in the SELECT statement for the cbobox (shown below).
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCalledInBy_AfterUpdate()
  2.    Me.txtCalledInByPhone = Me![cboCalledInBy].Column(3)
  3.    Me.txtBillTo = Me![cboCalledInBy].Column(2)
  4. End Sub
  5.  
Here is the full scenario:

Customer calls in, employee taking the phone call clicks on the [cboCalledInBy] and selects a name from the list. I want the two remaining fields ([txtCalledInByPhone] & [txtBillTo]) to be filled in automatically but with IF logic.

If the person selected has a [Mobile Phone] entry in their record then [txtCalledInByPhone] should use that if not then use [Business Phone] and if both are blank then return empty. Then for the "Bill To" if the record selected as [cboCalledInBy] has a [Company] name then [txtBillTo] should fill in with it but if they don't I want it to fill in with the callers name that was first selected [cboCalledInBy].

The other two boxes are just text boxes for a Tenant Name and Number, nothing special for them.

The SELECT statement for the [cboCalledInBy] filed is:
Expand|Select|Wrap|Line Numbers
  1. SELECT [ID], [Customer Name], [Company], [Business Phone], [Mobile Phone] 
  2. FROM [Customers Extended] 
  3. ORDER BY [Company];
  4.  
This raises the question: Customer Name becomes column 1, Company becomes column 2, Business Phone becomes column 3 and Mobile Phone becomes column 4. These are used in the VBA code shown above.

I suspect that the IF logic would have to be done on the STATEMENT so the column numbers in the VBA would be correct, I think?

The more I look for ways to accomplish this, the more I am lost.

Please Help!
Terry Echols
Jul 11 '16 #1

✓ answered by jforbes

Oh, I forgot to address your question about alternatives to IIF().

IIF() is great to use here and there as you can compact a thought onto one line in VBA. It also has it's uses in SQL and Expressions

But, the following is functionally equivalent to the previous versions, and bit easier to read and troubleshoot:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private mCalledInByPhone As String
  5. Private mBillTo As String
  6.  
  7. Private Sub cboCalledInBy_AfterUpdate()
  8.  
  9.     Dim sCalledInByPhone As String
  10.     Dim sBillTo As String
  11.     Dim sPhone As String
  12.     Dim sMobile As String
  13.  
  14.     If Nz(Me.cboCalledInBy.Value, 0) > 0 Then
  15.         sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  16.         If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  17.             sPhone = Nz(Me.cboCalledInBy.Column(3), "")
  18.             sMobile = Nz(Me.cboCalledInBy.Column(4), "")
  19.             If Len(sPhone) > 0 Then
  20.                 Me.txtCalledInByPhone.Value = sPhone
  21.             Else
  22.                 Me.txtCalledInByPhone.Value = sMobile
  23.             End If
  24.         End If
  25.  
  26.         sBillTo = Nz(Me.txtBillTo.Value, "")
  27.         If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  28.             Me.txtBillTo.Value = Nz(Me.cboCalledInBy.Column(2))
  29.         End If
  30.     Else
  31.         Me.txtCalledInByPhone.Value = ""
  32.         Me.txtBillTo.Value = ""
  33.     End If
  34.  
  35.     Call SaveCurrentCalledInValues
  36.  
  37. End Sub
  38.  
  39. Private Sub Form_Current()
  40.     Call SaveCurrentCalledInValues
  41. End Sub
  42.  
  43. Private Sub SaveCurrentCalledInValues()
  44.  
  45.     Dim sPhone As String
  46.     Dim sMobile As String
  47.  
  48.     If Nz(Me.cboCalledInBy.Value, 0) <> 0 Then
  49.         sPhone = Nz(Me.cboCalledInBy.Column(3), "")
  50.         sMobile = Nz(Me.cboCalledInBy.Column(4), "")
  51.         If Len(sPhone) > 0 Then
  52.             mCalledInByPhone = sPhone
  53.         Else
  54.             mCalledInByPhone = Me.txtCalledInByPhone.Value = sMobile
  55.         End If
  56.         mBillTo = Nz(Me.cboCalledInBy.Column(2), "")
  57.     Else
  58.         mCalledInByPhone = ""
  59.         mBillTo = ""
  60.     End If
  61.  
  62. End Sub
  63.  

22 1451
jforbes
1,107 Expert 1GB
Hopfully there isn't a typo in the following as I didn't use Access to help format or test this code, but this is representative of what I would do:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCalledInBy_AfterUpdate()
  2.    If Len(Nz(Me.txtCalledInByPhone.Value, "") = 0 Then
  3.       Me.txtCalledInByPhone = Me![cboCalledInBy].Column(3)
  4.    End If
  5.  
  6.    If Len(Nz(Me.txtBillTo.Value, "") = 0 Then
  7.       Me.txtBillTo = Me![cboCalledInBy].Column(2)
  8.    End If
  9. End Sub
The above code should test to see if the fields are filled in first, and if they aren't it will populate them from values in the ComboBox.
Jul 11 '16 #2
@jforbes
I got a Compile error (Syntax Error).
Expand|Select|Wrap|Line Numbers
  1. If Len(Nz(Me.txtCalledInByPhone.Value, "") = 0 Then
  2. If Len(Nz(Me.txtBillTo.Value, "") = 0 Then 
Both show in red.

I added the missing closing ")" to the end of the line to read:
Expand|Select|Wrap|Line Numbers
  1. If Len(Nz(Me.txtCalledInByPhone.Value, "")) = 0 Then
  2. If Len(Nz(Me.txtBillTo.Value, "")) = 0 Then 
This seems to be working but I have a question for you. If the operator makes a mistake in the selection process then attempts to choose the correct CalledInBy customer from the list, the other two txt fields don't change.

Example:
First time it works - all information is pulled correctly from the Query and two txt fields are pre-filled correctly.

But:
If they try to change the CalledInBy to another person it does not change the other two values.

Also, on a different note. What we are working on - when they are in Form View - [cboCalledInBy] is a dropdown box showing the Customer Name and Company (column 1 and column 2). Is there a way to make them both work as searchable? Meaning - as it is now - if they know the persons name (i.e. Customer Name) they can just start typing it and it will pull the list to that name. I'd like them to be able to do that with the Company name as well. The SELECT statement is bound to column 1 which is Customer Name - any way to make column 1 & 2 work in this manner?

Thanks,
Terry Echols

P.S. Thanks for this code I have been going nuts reading everything I could to find out how to accomplish this to no avail so much much appreciated.
Jul 11 '16 #3
jforbes
1,107 Expert 1GB
Both of those points can be addressed, but they are going to get a little tricky.

There are a couple approaches to your first point which boils down to only using the values from the ComboBox if the current TextBox has no value or if the Value matches what was previously selected in the ComboBox. Why this gets tricky, is that your user could flip around and select an endless amount or records on the Combobox and there isn't a built in method in Access to track all the different Values that are selected. There is an .OldValue property that could work here, but I don't think it will as the .OldValue only updates on the Save of a record and the User could select a value in the ComboBox multiple times before the .OldValue gets updated, which would make the .OldValue unreliable. So a slightly more complex way is to create some public variables to hold the current ComboBox values and update them when ever the value changes. Then the Public variables can be referred to, to decide on what to do.

Again, there maybe errors with the code, so you may have to debug it. This would be the code for the Form if I were to do it. Note the top two lines are Form level variable declarations:
Expand|Select|Wrap|Line Numbers
  1. Private mCalledInByPhone As String
  2. Private mBillTo As String
  3.  
  4. Private Sub cboCalledInBy_AfterUpdate()
  5.  
  6.     Dim sCalledInByPhone As String
  7.     Dim sBillTo As String
  8.  
  9.     sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")    
  10.     If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone ) = 0 Then
  11.         Me.txtCalledInByPhone.Value = Me.cboCalledInBy.Column(3)
  12.     End If
  13.  
  14.     sBillTo = Nz(Me.txtBillTo.Value, "")    
  15.     If mBillTo = sBillTo Or Len(sBillTo ) = 0 Then
  16.         Me.txtBillTo.Value = Me.cboCalledInBy.Column(2)
  17.     End If
  18.  
  19.     Call SaveCurrentCalledInValues
  20.  
  21. End Sub
  22.  
  23. Private Sub Form_Current()
  24.     Call SaveCurrentCalledInValues
  25. End Sub
  26.  
  27. Private Sub SaveCurrentCalledInValues()
  28.     mCalledInByPhone = Nz(Me.cboCalledInBy.Column(3), 0)
  29.     mBillTo = Nz(Me.cboCalledInBy.Column(2)"")
  30. End Sub
So in the above the method SaveCurrentCalledInValues saves off the current values of the ComboBox into Form level variables to that previous values are readily available after the ComboBox's value is changed. This save was put into it's own method, so that it can be called in multiple places, like the OnCurrent event as well as the AfterUpdate.

Again, you may have to tweak the code to get it working.

To your second point, that is a big one and if you need to discuss it much, you should start a new thread as we like to keep threads here to one topic because it makes for clean and easy to read threads. This is a similar question for your second point, you may want to look at it to see if it gives you any ideas: choose item in a ComboBox as we Type the contained text...
Jul 11 '16 #4
Hi:

I've finally had some time to put this code to the test and have an issue I need help with.

The current code:
Expand|Select|Wrap|Line Numbers
  1. Private mCalledInByPhone As String
  2. Private mBillTo As String
  3.  
  4. Private Sub cboCalledInBy_AfterUpdate()
  5.  
  6.     Dim sCalledInByPhone As String
  7.     Dim sBillTo As String
  8.  
  9.     sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  10.     If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  11.         Me.txtCalledInByPhone.Value = Me.cboCalledInBy.Column(3)
  12.     End If
  13.  
  14.     sBillTo = Nz(Me.txtBillTo.Value, "")
  15.     If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  16.         Me.txtBillTo.Value = Me.cboCalledInBy.Column(2)
  17.     End If
  18.  
  19.     Call SaveCurrentCalledInValues
  20.  
  21. End Sub
  22.  
  23. Private Sub Form_Current()
  24.     Call SaveCurrentCalledInValues
  25. End Sub
  26.  
  27. Private Sub SaveCurrentCalledInValues()
  28.     mCalledInByPhone = Nz(Me.cboCalledInBy.Column(3), 0)
  29.     mBillTo = Nz(Me.cboCalledInBy.Column(2), "")
  30. End Sub
What is supposed to happen is the CalledInByPhone and BillTo are based on the cboCalledInBy. The select statement is:

Expand|Select|Wrap|Line Numbers
  1. SELECT [ID], [Customer Name], [Company], [Business Phone], [Mobile Phone] FROM [Customers Extended] ORDER BY [Customer Name]; 
Making it Customer Name (col 1), Company (col 2) and here is the tricky part, to use col 3 as it is now is using Business Phone. I need it to use if logic to select the stored value. I need it to use Mobile Phone is there is one stored for the customer if not use Business Phone.

The code now is only pulling Business Phone (col 3). What would I need to do to either the select statement or the VBA code to make it use the if/then or logic?

Thanks,
Terry Echols
Jul 25 '16 #5
jforbes
1,107 Expert 1GB
This might do it for you, depending on how your data is structured, if you have Blanks instead of Nulls in your Phone Numbers, the NZ will need to be changed to an If Statement or an IIF().

The idea behind this is to use Column 4 instead of Column 3 whenever Column 3 is Null. There are two places where Column 3 is used, so they would both need to test for Nulls.
Expand|Select|Wrap|Line Numbers
  1. Private mCalledInByPhone As String
  2. Private mBillTo As String
  3.  
  4. Private Sub cboCalledInBy_AfterUpdate()
  5.  
  6.     Dim sCalledInByPhone As String
  7.     Dim sBillTo As String
  8.  
  9.     sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  10.     If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  11.        Me.txtCalledInByPhone.Value = Nz(Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
  12.     End If
  13.  
  14.     sBillTo = Nz(Me.txtBillTo.Value, "")
  15.     If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  16.         Me.txtBillTo.Value = Me.cboCalledInBy.Column(2)
  17.     End If
  18.  
  19.     Call SaveCurrentCalledInValues
  20.  
  21. End Sub
  22.  
  23. Private Sub Form_Current()
  24.     Call SaveCurrentCalledInValues
  25. End Sub
  26.  
  27. Private Sub SaveCurrentCalledInValues()
  28.     mCalledInByPhone = Nz(Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
  29.     mBillTo = Nz(Me.cboCalledInBy.Column(2), "")
  30. End Sub
Jul 26 '16 #6
There are going to be null values in both business and mobile phone fields.

Which Nz statements will have to be changed to IIf?

And one more question has arisen now that I'm implementing the system.

When a customer does not have a company name I'd like the txtBillTo to use the cboCalledInBy name, how would I do that exactly?

I'm good, usually, at re-working code but designing it is another animal altogether.
Jul 26 '16 #7
jforbes
1,107 Expert 1GB
You'll probably be fine with the NZ() method as it sounds like that is what you are using. Just for clarification on the Null vs Blank scenario, a little light reading: What is the difference between "" and Null?


The following code is pretty similar but the First Line is expecting Nulls, Line 3 would also handle Blanks. Why wouldn't you just use the Line 3? ... in this case it is just a preference really, but sometimes it does matter.
Expand|Select|Wrap|Line Numbers
  1. = Nz(Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
  2. to
  3. = Iff(Len(Me.cboCalledInBy.Column(3)) > 0, Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
When a customer does not have a company name I'd like the txtBillTo to use the cboCalledInBy name, how would I do that exactly?
I thought that scenario was already being addressed. Are you asking to do something that isn't being done already?
Jul 26 '16 #8
I am so lost in trial and error. There are two instances of
Expand|Select|Wrap|Line Numbers
  1. Nz(Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
One in the code for [cboCalledInBy_AfterUpdate()] and one in the [Private Sub SaveCurrentCalledInValues()]

Do I change them both? I did but got errors. When I used the new IIF code in the Sub for SaveCurrent... I got runtime error 94, invalid use of NULL.

I have tried the new code in the SaveCurrent... Sub and not in the AfterUpdate... and get error 94; if I reverse that I get no errors but the code isn't working.

This is the code that is running now, it throws no errors but doesn't work:
Expand|Select|Wrap|Line Numbers
  1. Private mCalledInByPhone As String
  2. Private mBillTo As String
  3.  
  4. Private Sub cboCalledInBy_AfterUpdate()
  5.  
  6.     Dim sCalledInByPhone As String
  7.     Dim sBillTo As String
  8.  
  9.     sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  10.     If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  11.        Me.txtCalledInByPhone.Value = Nz(Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
  12.     End If
  13.  
  14.     sBillTo = Nz(Me.txtBillTo.Value, "")
  15.     If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  16.         Me.txtBillTo.Value = Nz(Me.cboCalledInBy.Column(2), Me.cboCalledInBy.Column(1))
  17.  
  18.     End If
  19.  
  20.     Call SaveCurrentCalledInValues
  21.  
  22. End Sub
  23.  
  24. Private Sub Form_Current()
  25.     Call SaveCurrentCalledInValues
  26. End Sub
  27.  
  28. Private Sub SaveCurrentCalledInValues()
  29.     mCalledInByPhone = IIf(Len(Me.cboCalledInBy.Column(3)) > 0, Me.cboCalledInBy.Column(3), Me.cboCalledInBy.Column(4))
  30.     mBillTo = IIf(Len(Me.cboCalledInBy.Column(2)) > 0, Me.cboCalledInBy.Column(2), Me.cboCalledInBy.Column(1))
  31. End Sub
I've tried moving things around, adding watches and generally tried to "watch/see" what the code is doing to no avail. I'm thoroughly lost now.

The code above doesn't work the way I need it to and can't figure out why. On the surface it appears it would be doing what it should but it's not.

As to the txtBillTo being filled in if Company is NULL/Blank that isn't working either with the new or the old code.

I'm so lost now.

Terry
Jul 27 '16 #9
jforbes
1,107 Expert 1GB
How about this then, I went and created an example database. In it is the example we have been working with.

While I was creating it, I realized that you might not want what we were working on. ... That I might have not fully understood what you were attempting to do. There are a lot of ways that stuff like what we are doing can be accomplish and for different goals. The goal I originally understood and which is quite possibly what you are after is to save off the values of the Customer along with the call. This is a common practice, that way if the phone numbers or addresses change over time, then there is a record of what was used. This is often done in Invoicing so that there is a complete record of who and what was invoiced. So in the Example Database, this approach is utilized on the "CallDetails_SaveAllDetails" Form.

The other common approach is utilizing full normalization by only storing the Key to the Customer Table and then only displaying the other information from the Customer on the Form. I made up one of this style in the Form named "CallDetails_JustTheBasics". It uses unbound controls to display the other information from the Customer table.
Attached Files
File Type: zip CallTracker.zip (29.7 KB, 65 views)
Jul 27 '16 #10
Mr Forbes:

You are correct in that I don't want the "Customer/Customer Extended" table data changed only retrieved. The customer info should stay the same in those tables but the calls details written/stored in the "Calls" table can be different.

I tried the new code this morning "SaveAllDetails" but I'm getting error 94 and it stops on this line:
Expand|Select|Wrap|Line Numbers
  1. mCalledInByPhone = IIf(Len(Nz(Me.cboCalledInBy.Column(3), "")) > 0, Nz(Me.cboCalledInBy.Column(3), ""), Me.cboCalledInBy.Column(4))
Thank you so much for the help, BTW. It is much appreciated.

Terry
Jul 28 '16 #11
jforbes
1,107 Expert 1GB
I think if you replace the line with the following it should work:
Expand|Select|Wrap|Line Numbers
  1. mCalledInByPhone = IIf(Len(Nz(Me.cboCalledInBy.Column(3), "")) > 0, Nz(Me.cboCalledInBy.Column(3), ""), Nz(Me.cboCalledInBy.Column(4),""))
I'm not a fan off IIf() statements, but it seemed like the best fit for what is going on here. If I remember correctly, one of the drawbacks of an IIF() is that the entire line is evaluated, so if a Null shows up for any part of an IIF() it can wreak havoc on the entire line.

You may already know this, but if you run into something like this and want to troubleshoot it, you can place a breakpoint on the line, by right-clicking it and selecting Toggle|Breakpoint. Then you can use the mouse to hover over the line and see what values the different parts hold. My guess in this case if you hovered over the last part it would tell you it's a Null. Debugging is a fairly deep subject with a steep learning curve, but it is a valuable tool. If your interested in it, this link is a good place to start: Debugging in VBA
Jul 28 '16 #12
Thanks for the Debugging info I have tried to find good resources on that but came up short. I'll take an in-depth look at the info at that link when I have more time.

An update:
When I first implemented the code the first thing I need to do was search for an address, that is when the error was thrown. But I have been using the code for a couple of hours now and have not had another issue - YET.

I can't tell you how much I appreciate your help, information and code. Thank you.

Terry
Jul 28 '16 #13
Update:

I was wrong about the error 94. It gets thrown ONLY when I add a new customer.

This form works by a pop up message when a name is typed in for Called In By that is not in the table asking if we want to add it. Say yes and the Customer Details form opens with the name prefilled. After adding all the customer details and closing the customer form the cursor goes back to the Called In By field, after hitting tab is when the error is thrown - BUT - it is only thrown on the Mobile Phone entry. If I add the number to the Business Phone field no error is thrown only if I add the number to Mobile Phone is it a problem.

Any idea on this one? This is the only issue I can find after a few hours or working with this code.

Terry
Jul 28 '16 #14
Update:

I spoke too soon. All is working EXCEPT where a Mobile Phone is used. If there is a Business Phone no problems what so ever. The 94 error is thrown when either the situation I described above takes place, or, as I just found out, when I tried to update a call record to a different customers that, of course, has only a mobile phone listed, the error was thrown again.

So, as you say, you don't like using the IIF statements, I concur now, what would be an alternative to use to accomplish my goals?

In a nutshell, it seems to throw the 94 error on any customers that has ONLY a mobile phone listed in the Customers table, or as I'm using, the Customer Extended Query.

Terry
Jul 28 '16 #15
jforbes
1,107 Expert 1GB
I have a feeling that it's missing some NZ()

Maybe this would work?
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private mCalledInByPhone As String
  5. Private mBillTo As String
  6.  
  7. Private Sub cboCalledInBy_AfterUpdate()
  8.  
  9.     Dim sCalledInByPhone As String
  10.     Dim sBillTo As String
  11.  
  12.     If Nz(Me.cboCalledInBy.Value, 0) > 0 Then
  13.         sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  14.         If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  15.            Me.txtCalledInByPhone.Value = IIf(Len(Nz(Me.cboCalledInBy.Column(3), "")) > 0, Nz(Me.cboCalledInBy.Column(3), ""), Nz(Me.cboCalledInBy.Column(4), ""))
  16.         End If
  17.  
  18.         sBillTo = Nz(Me.txtBillTo.Value, "")
  19.         If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  20.             Me.txtBillTo.Value = Nz(Me.cboCalledInBy.Column(2))
  21.         End If
  22.     Else
  23.         Me.txtCalledInByPhone.Value = ""
  24.         Me.txtBillTo.Value = ""
  25.     End If
  26.  
  27.     Call SaveCurrentCalledInValues
  28.  
  29. End Sub
  30.  
  31. Private Sub Form_Current()
  32.     Call SaveCurrentCalledInValues
  33. End Sub
  34.  
  35. Private Sub SaveCurrentCalledInValues()
  36.     If Nz(Me.cboCalledInBy.Value, 0) <> 0 Then
  37.         mCalledInByPhone = IIf(Len(Nz(Me.cboCalledInBy.Column(3), "")) > 0, Nz(Me.cboCalledInBy.Column(3), ""), Nz(Me.cboCalledInBy.Column(4), ""))
  38.         mBillTo = Nz(Me.cboCalledInBy.Column(2), "")
  39.     Else
  40.         mCalledInByPhone = ""
  41.         mBillTo = ""
  42.     End If
  43. End Sub
Jul 28 '16 #16
jforbes
1,107 Expert 1GB
Oh, I forgot to address your question about alternatives to IIF().

IIF() is great to use here and there as you can compact a thought onto one line in VBA. It also has it's uses in SQL and Expressions

But, the following is functionally equivalent to the previous versions, and bit easier to read and troubleshoot:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private mCalledInByPhone As String
  5. Private mBillTo As String
  6.  
  7. Private Sub cboCalledInBy_AfterUpdate()
  8.  
  9.     Dim sCalledInByPhone As String
  10.     Dim sBillTo As String
  11.     Dim sPhone As String
  12.     Dim sMobile As String
  13.  
  14.     If Nz(Me.cboCalledInBy.Value, 0) > 0 Then
  15.         sCalledInByPhone = Nz(Me.txtCalledInByPhone.Value, "")
  16.         If mCalledInByPhone = sCalledInByPhone Or Len(sCalledInByPhone) = 0 Then
  17.             sPhone = Nz(Me.cboCalledInBy.Column(3), "")
  18.             sMobile = Nz(Me.cboCalledInBy.Column(4), "")
  19.             If Len(sPhone) > 0 Then
  20.                 Me.txtCalledInByPhone.Value = sPhone
  21.             Else
  22.                 Me.txtCalledInByPhone.Value = sMobile
  23.             End If
  24.         End If
  25.  
  26.         sBillTo = Nz(Me.txtBillTo.Value, "")
  27.         If mBillTo = sBillTo Or Len(sBillTo) = 0 Then
  28.             Me.txtBillTo.Value = Nz(Me.cboCalledInBy.Column(2))
  29.         End If
  30.     Else
  31.         Me.txtCalledInByPhone.Value = ""
  32.         Me.txtBillTo.Value = ""
  33.     End If
  34.  
  35.     Call SaveCurrentCalledInValues
  36.  
  37. End Sub
  38.  
  39. Private Sub Form_Current()
  40.     Call SaveCurrentCalledInValues
  41. End Sub
  42.  
  43. Private Sub SaveCurrentCalledInValues()
  44.  
  45.     Dim sPhone As String
  46.     Dim sMobile As String
  47.  
  48.     If Nz(Me.cboCalledInBy.Value, 0) <> 0 Then
  49.         sPhone = Nz(Me.cboCalledInBy.Column(3), "")
  50.         sMobile = Nz(Me.cboCalledInBy.Column(4), "")
  51.         If Len(sPhone) > 0 Then
  52.             mCalledInByPhone = sPhone
  53.         Else
  54.             mCalledInByPhone = Me.txtCalledInByPhone.Value = sMobile
  55.         End If
  56.         mBillTo = Nz(Me.cboCalledInBy.Column(2), "")
  57.     Else
  58.         mCalledInByPhone = ""
  59.         mBillTo = ""
  60.     End If
  61.  
  62. End Sub
  63.  
Jul 28 '16 #17
I tried both sets of code on the same 4 customers for testing. I selected customers with:

Mobile Phone Only w/company - pulls company but not phone
Both Mobile & Business Phone w/company - pulls business phone and company
Mobile Only no/company - pulls no phone number
Both Mobile & Business Phone no/company - pulls business phone

Both sets of code does the same thing - it won't pull the mobile number. Same if I create a new customers from the call details form. If I create a new call and type a name not in the customers table it takes me to the customer details page to create them. If only a mobile phone is entered the call details form doesn't use it.

I poured over both sets of code and can't see why it's not pulling the mobile phone.

Neither sets of code is throwing the 94 error again - that's good. Now that damn pesky mobile phone...

Thanks,
Terry
Jul 29 '16 #18
I played around with debugging and it appears to me that the mobile phone is being completely ignored. Every value is NULL when you hover over the variable where mobile phone should be pulled. I don't exactly understand why.

Terry
Jul 29 '16 #19
jforbes
1,107 Expert 1GB
Sounds like progress.

Things to check:
  • Make sure the Mobile Number is visible in the dropdown list for cboCalledInBy
  • Make sure the .ColumnCount for cboCalledInBy is set to 5. (This needs to be equal to the number of columns for your ComboBox)
  • Make sure the Mobile Number is included in the RowSource of cboCalledInBy
Jul 29 '16 #20
It's working but I do want to make one change. I want to pull the Mobile Phone by default so IF a customer has both I'd like to pull Mobile. It's working now except for those customers that have both. It pulls the Business but I want it to pull the Mobile (if one exist).

I had the column count as 3 to hide the phone numbers, I didn't know that that would block the VAB code from working on those columns. I have them all defined now and simply used 0" to still hide them.

Getting there.

Thanks
Jul 29 '16 #21
jforbes
1,107 Expert 1GB
Yeah, understanding how Access implements the ComboBox takes a little while and some trial an error.

To make the Mobile Number the Default, all you should have to do is change this:
Expand|Select|Wrap|Line Numbers
  1. If Len(sPhone) > 0 Then
to:
Expand|Select|Wrap|Line Numbers
  1. If Len(sMobile) = 0 Then
in two places.
Jul 29 '16 #22
I had thought about that change but wasn't entirely sure if that would do it. Glade to know I was on the right track though.

Yay! Brilliant. I can't thank you enough.

I will be posting a new thread for a separate issue. I hope you'll chime in on it once I get it posted. Although, you may want to set up the Access Call Tracker template for this one.

I would compact and send you my database that we've been working on but I don't know how.

Thanks again.
Terry
Jul 29 '16 #23

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

Similar topics

12
by: Steven T. Hatton | last post by:
In the following code, the class B will not compile if the function da is uncommented. I took exactly the same code, and turned it into templates. Never used the template parameter in anything but...
1
by: Joe Saliba | last post by:
hi, how to call an access report from a vb application ?? i don't want to make a report from vb thx. *** Sent via Developersdex http://www.developersdex.com ***
0
by: Steve | last post by:
Hi i am currently playing around with the 'Service call managment' database and i am wondering if someone could tell me how a job is meant to be finished off. There is a report for finished and...
2
by: tonytony24 | last post by:
Hi All: I was wondering if there's a simple way to call a MS Access Module through either Command Prompt MS Script any other way... Thanks for the response.
4
by: Anns | last post by:
Reference: Service Call Management Template http://office.microsoft.com/en-us/templates/TC010184671033.aspx?CategoryID=CT011366681033 I have just one question regarding this free template and...
2
by: eric.goforth | last post by:
Hello, What happens if you call an xsl template if you call it without setting the values of all it's parameters, I assume that the parameters will be either null or an empty string and the...
1
by: shuvo3000 | last post by:
Hi i am making a small software. I need some reports which need a bit details section which I can not make from VB data report...so I made that with Access Report. Now is there any way to call that...
1
by: cooldude | last post by:
I have a gridview component and it has a template field associated with it. However when I used gridview.Cells.Text it is null or balnk. Also the template field has not control associated with...
1
by: Ruki | last post by:
I want to overload function to swap two others types, for example, type<T>, T* and so on, but I can't compile the following code at VC 6.0. The compiler says : error C2667: 'swap' : none of 2...
4
by: l.s.rockfan | last post by:
Hello, how do i have to call an inherited, templated class constructor from the initializer list of the inheriting, non-templated class constructor? example code: template<typename T>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.