Overruling Expression in Text Box.

NBVC

Only trying to help
Local time
Yesterday, 22:42
Joined
Apr 25, 2008
Messages
317
HI,

I have a text box that autopopulates with a Dlookup() function:

=DLookUp("NAME","SYSADM_CUSTOMER","ID = '" & [CustID] & "'")

based on entry made in ComboBox CustID.

I also want to be able to type in anything I want if I leave CustID combobox blank.

It is not letting me. Giving me an error that it is bound to the expression above.

Is there a way to overrule that expression as needed?
 
It looks like you need to put the dlookup() thing in the custid combo box after update event and check for null...
 
Not sure what you mean.

The user selects an ID from the ComboBox and I want the text box to autocomplete with the associated Name for that Id found in the SYSADM_CUSTOMER table. But I want the user also to able to type in a customer name in the text box without selecting an ID from the combobox.

This is for creating Quotes... and not all customers we quote are in the customer database.
 
Have you ever put code in a control event?
 
No, I don't really use Access much... just learning as I go.
 
I tried this:

Code:
 Private Sub CustID_AfterUpdate()
Dim TextStuff As Variant
   TextStuff = DLookup("NAME", "SYSADM_CUSTOMER", "ID = '" & [CustID] & "'")
   If (Not IsNull(TextStuff)) Then Me![Text7] = TextStuff

End Sub

but giving me an error on Me![Text7] = TextStuff
 
Try...

Code:
Private Sub CustID_AfterUpdate()
   Dim TextStuff As String

   If me.custid & "" <> "" then
       TextStuff = DLookup("NAME", "SYSADM_CUSTOMER", "ID = '" & [CustID] & "'")
   Me![Text7] = TextStuff

End Sub
 
There is an END IF missing, but otherwise it worked.. but only once.

After I typed in the text box, then I blanked it out and tried to choose from the combobox it gave me an error and I could not get out of it....

see attached for error message.
 

Attachments

  • AccessPic.gif
    AccessPic.gif
    8.5 KB · Views: 95
Something don't seem correct about this whole drill... Let me think on it for a minute...
 
What is the customer tied to in the form? A sales order or something like that?
 
No it isn't tied to anything at the moment. Both fields ID and NAME are in the same table

I will be tying shipto address table later...
 
No it isn't tied to anything at the moment. Both fields ID and NAME are in the same table

I will be tying shipto address table later...

Just as an aside, you really shouldn't have a field called "Name" it is an access reserved word. And can cause problems for you.
 
Can you post a sample database of what you have so far? I don't understand what you are trying to do but something tells me there's an underlying data model issue.
 
I just have a table CUSTOMER that comes from my ERP database.

It has multiple fields in it of which 2 are ID and NAME

in the form, I want to able to either choose from a list of ID's linked to the CUSTOMER or just leave it blank.

IF I choose from the list or type an existing ID, then the textbox, TEXT7 should automatically populate with the corresponding NAME from the CUSTOMER table.

IF I leave the combo box blank, then I want to be able to type in any text in TEXT7.

I don't yet have a QUOTE table where I will be storing the results of the form. Is that the problem?
 
Yes I think not having the quotes table is this problem, in my understanding at least. So when you choose a customer or type in a new one, do you want to store this in a quote?
 
I am trying to create an application outside our ERP database that will update a Quote Table.

The current Quote Application in the system doesn't do everything our Sales staff wants it to do, so they asked if I can come up with something... even though I am not an avid Access user.

So basically, I am adding flexibility to the built in Quote Application.

Should I create an empty QUOTE table that has the matching fields to the ERP table and link it to the ERP so that I am automatically updating the database?

I am going to have to figure out also how to autonumber so that I can attach to the bottom of the table.
 
So today your quotes reside in a third party application, not your ERP and not an Access database?
 
Actually, the QUOTE table resides in the same ERP system.. We just have not used it and now they are finding the need to try it... but they don't feel it has enough flexibility.

So the ERP has the QUOTE table, CUSTOMER TABLE, etc. I want to download the CUSTOMER TABLE and QUOTE TABLE and only update the QUOTE Table through ACCESS forms.
 
Here is the problem. Access needs hard-and-fast rules to define the contents of something. Let's say you have two boxes, [TBBound] and [TBFormula]

You tell us that you want something computable to be placed in [TBFormula] but that you also want it to be something you can permanently and manually override. In order for that to happen, [TBFormula] must be bound to a recordset. I.e. you have to store it to permanently bind it with an override.

Let's say that [TBFormula], if not overridden, is computed from [TBBound]. When you place a value in [TBBound], you could use a TBBound_LostFocus() event to put something in [TBFormula] if it is still empty or null or blank or whatever.

Here's your dilemma. A control (such as [TBFormula]) can be unbound, bound, or computed by formula. That's it. That's all the choices you have.

If it is unbound, then it never takes on any value from an underlying recordset. You could therefore populate it from the Form_Current routine by computing from something else on the form. Like from [TBBound].

If you want to REMEMBER that for record #2 you overrode the computation, then the control must be BOUND because only bound controls have memories of what they were. If the control is purely computed (i.e. a formula), it has no place to remember anything. If it is unbound, it has no memory, either.

This is the catch. If the form calls up a new record and you don't happen to define a new value for the field., you will compute it and store it in the text box. If you save the record, you save the computed value, which acts as though it were an override value the next time that the same record comes up again.

If what I just described doesn't make sense to you, then you need to do some more reading. This is basic form-based controls 101. If this is not the behavior you wanted, you will have to find a way to "cheat" Access rules on control behavior. Or maybe decide to not really do this in the first place.
 
Actually, the QUOTE table resides in the same ERP system.. We just have not used it and now they are finding the need to try it... but they don't feel it has enough flexibility.

So the ERP has the QUOTE table, CUSTOMER TABLE, etc. I want to download the CUSTOMER TABLE and QUOTE TABLE and only update the QUOTE Table through ACCESS forms.

Can you link directly to the erp tables or are you stuck with having to pull the data manually?
 

Users who are viewing this thread

Back
Top Bottom