A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

On Open Set Field Value



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2008, 04:48 PM posted to microsoft.public.access.forms
ChrisG
external usenet poster
 
Posts: 30
Default 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  
Old April 28th, 2008, 06:15 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default 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  
Old April 28th, 2008, 06:23 PM posted to microsoft.public.access.forms
George Nicholson
external usenet poster
 
Posts: 791
Default 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  
Old April 28th, 2008, 06:33 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default 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  
Old April 29th, 2008, 02:47 PM posted to microsoft.public.access.forms
ChrisG
external usenet poster
 
Posts: 30
Default 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  
Old April 29th, 2008, 06:32 PM posted to microsoft.public.access.forms
George Nicholson
external usenet poster
 
Posts: 791
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.