If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
On Open Set Field Value
How can I set a field value when a user opens form?
I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
#2
|
|||
|
|||
On Open Set Field Value
Use the Default Value property of the control bound to the field you want to
populate. Set it in form design view using the properties dialog box. Also, when you want to address controls on a form you are opening, use the Load event rather than the Open event. The Open event may be too soon and the control references may not yet be established. The Open event is better used when you need to make a decision on whether to allow the form to open or cancel the open using Cance = True. -- Dave Hargis, Microsoft Access MVP "ChrisG" wrote: How can I set a field value when a user opens form? I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
#3
|
|||
|
|||
On Open Set Field Value
Try setting it in the Form_Current event:
If Me.NewRecord Then shipQteType = "Pullbox" End If Even if your form is only used to add new records, it's a little safer. -- HTH, George "ChrisG" wrote in message ... How can I set a field value when a user opens form? I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
#4
|
|||
|
|||
On Open Set Field Value
Safer than using the control's Default Value property?
How so? -- Dave Hargis, Microsoft Access MVP "George Nicholson" wrote: Try setting it in the Form_Current event: If Me.NewRecord Then shipQteType = "Pullbox" End If Even if your form is only used to add new records, it's a little safer. -- HTH, George "ChrisG" wrote in message ... How can I set a field value when a user opens form? I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
#5
|
|||
|
|||
On Open Set Field Value
I agree normally I would use control's Default Value property, but I negected
to tell you there are two values needed and depending on which form is used is a value assigned. Thank you both for your prompt answers and teaching me a little bit more about Access. -- ChrisG "Klatuu" wrote: Safer than using the control's Default Value property? How so? -- Dave Hargis, Microsoft Access MVP "George Nicholson" wrote: Try setting it in the Form_Current event: If Me.NewRecord Then shipQteType = "Pullbox" End If Even if your form is only used to add new records, it's a little safer. -- HTH, George "ChrisG" wrote in message ... How can I set a field value when a user opens form? I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
#6
|
|||
|
|||
On Open Set Field Value
Dave, my "safer" comment wasn't meant in response to your post (that hadn't
appeared yet). I was simply trying to indicate that it would be safer to *verify* that you were dealing with a new record rather than *assume* you were, even when opening a form in Data entry mode, since that is soooo easy to change somewhere down the line. Of course, setting DefaultValue as you suggested accomplishes the same thing since it is only applied to NewRecords. -- HTH, George "Klatuu" wrote in message ... Safer than using the control's Default Value property? How so? -- Dave Hargis, Microsoft Access MVP "George Nicholson" wrote: Try setting it in the Form_Current event: If Me.NewRecord Then shipQteType = "Pullbox" End If Even if your form is only used to add new records, it's a little safer. -- HTH, George "ChrisG" wrote in message ... How can I set a field value when a user opens form? I want to set ShpQteType = "Pullbox" when a user opens form SHPQTE PB Form uses a Query (ShpQte Query) to enter new data I tried to do this using the Expression builder =[SHPQTE]![ShipQteType] = "Pullbox" But I got an error. Also Tried Code builder and it didn't set the value in the table. Private Sub Form_Open(Cancel As Integer) Dim shipQteType As String shipQteType = "Pullbox" End Sub -- ChrisG |
Thread Tools | |
Display Modes | |
|
|