Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Default Value for Text Box 1

Status
Not open for further replies.

ShellyL

Technical User
Mar 30, 2004
24
US
I have a form where I want users to be able to edit or add items for an order. “OrderNumber” is a key field.

Because the Order Number is critical, I'd like to have that field locked so the user cannot update it.
This means they also can’t update it on the blank row where the new item would normally be added (it’s current default is null).

So, can I have that text box for Order Number on the blank row default to the Order Number at hand? Or do I need to allow that box to be updated all around? (Can I have my cake and eat it too???)

More info: The Form is “EditOrders”. It is based on a Query called “SelectOrders” which is basically “Select * from table Orders where OrderNumber = [Enter Order Number]”. It’s a Continuous Form that allows additions. Order Number is a required field.
 
Shelly,
I'm not sure how your order number works if it's not a unique field. is the table "Orders" an order line table, which points to an order header table? If not, you may want to consider breaking it up this way.

That said, here's how I would accomplish what you're after:

Instead of prompting for what to search for in the query, use an inputbox on form_load. Keep the value in a variable so you can use it multiple places.

example:

on form_load()
intOrderNum = inputbox("Insert prompt here")
me.form.recordsource = "Select * from table Orders where OrderNumber = " & intOrderNum
me.txtOrderNumber.defaultvalue = intOrderNum
me.requery
end sub

This is quick and dirty 'code', but you get the idea.

Oh, and be sure to set the locked property of txtOrderNumber to true.

Hope this helps!

RoppeTech

- RoppeTech
 
Works great! Here's the exact code I used:

Private Sub Form_Load()
intOrder_Num = InputBox("Enter Order Number")
Me.Form.RecordSource = "Select * from Orders where Order_Num = " & intOrder_Num
Me.TxtOrder_Num.DefaultValue = intOrder_Num
Me.Requery
End Sub

And I needed to make sure the "Name" of the text box on the form was TxtOrder_Num.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top