Full Version: Where Are Form Default Values Coming From
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
gloworm
I have a form that opens from a button on another form.
When the new form opens, there are some fields that have default values in them.
I have looked and do not know where these values are coming from.
I have looked in the database and the fields for record A that have default values assigned on the form, are in fact blank ion the database.

I also noticed that if I open the form from the navigation menu, it has many defaults assigned to it.
This is double weird because this form with default values on it, gets its bill of lading number from a form that isnt even open.
In essence, these default values shouldnt even be on the form because its parent form is closed.
I should get a blank form, but I get one with many defaults.

How do I get rid of these defaults?
cpetermann
gloworm,

What is your first name? smile.gif

Without seeing the db it's difficult to say where to look.
Could you make a copy of your db,
remove all but a few records so that we can see the problem
replace sensitive data with "dummy data"
compact & repair
zip and attach

Thanks
gloworm
QUOTE (cpetermann @ May 29 2012, 08:50 AM) *
gloworm,

What is your first name? smile.gif

Without seeing the db it's difficult to say where to look.
Could you make a copy of your db,
remove all but a few records so that we can see the problem
replace sensitive data with "dummy data"
compact & repair
zip and attach

Thanks



My name is Mike.
Thanks for asking.

I have just realized that the data, is the first record in the table.
Now that I know what the data is, how do I make the form not show the first record in the table it is referenced to?
missinglinq
Is this an app that you created or one that you've inherited?

Where did you check for Default Values? They can be set either at the Table-level or the Form-level.

As Cynthia has said, it's impossible for anyone here to troubleshoot this kind of thing without actually laying eyes on your file. It would also be helpful to know what Form you're talking about and what exact action(s) are needed to recreate what you're seeing.

Linq ;0)>
jleach
Usually in the Form's Open event we'll put DoCmd.GotoRecord , , acNewRecord

Also check the DefaultValue of each control and table field to see if there's defaults set up there.

hth
gloworm
QUOTE (missinglinq @ May 29 2012, 09:00 AM) *
Is this an app that you created or one that you've inherited?

Where did you check for Default Values? They can be set either at the Table-level or the Form-level.

As Cynthia has said, it's impossible for anyone here to troubleshoot this kind of thing without actually laying eyes on your file. It would also be helpful to know what Form you're talking about and what exact action(s) are needed to recreate what you're seeing.

Linq ;0)>


I inherited the project.
The previous person was let go and I have nobody here to help me out for the most part.

There is a sister form that comes up blank when you open it by itself, no defaults.
When I open the form I started this thread about, it has defaults.

QUOTE (jleach @ May 29 2012, 09:01 AM) *
Usually in the Form's Open event we'll put DoCmd.GotoRecord , , acNewRecord

Also check the DefaultValue of each control and table field to see if there's defaults set up there.

hth


On the even tab of the form, there are 3 events:

Private Sub Form_Dirty(Cancel As Integer)
UpdSaved = False
End Sub




Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

Select Case Screen.ActiveControl.Name
Case "Consignee"
stDocName = "frmConsignee_LU"
Case "ShipperCode"
stDocName = "frmShipper_LU"
End Select

Select Case KeyCode
Case vbKeyF3
DoCmd.OpenForm stDocName
End Select
End Sub




Private Sub Form_Open(Cancel As Integer)
Static MouseHook As Object
Set MouseHook = NewMouseHook(Me)
End Sub



I dont see a mention like you described.

Also like I said in my second post, the default data it is showing me is the information for the first record in the table the form references.
If I can stop it showing the first record in the table, it would be a big help.
jleach
The events you describe are those that are implemented in VBA. Go to the Properties dialog of the form, and click the Events tab for a complete listing of available events (in the three events you mention, you'll see [Event Procedure] displayed in the list). Make sure the form itself is selected rather than the detail section or any control, they'll have their own associated events.

Double click the blank box next to the even name (OnOpen), and you should be taken to the VBA window with the cursor between the following:

CODE
Private Sub Form_Open(Cancel As Integer)

End Sub


This is where you'll put the code to tell it to go to a new record when the form is opened.

hth
gloworm
QUOTE (jleach @ May 29 2012, 09:15 AM) *
The events you describe are those that are implemented in VBA. Go to the Properties dialog of the form, and click the Events tab for a complete listing of available events (in the three events you mention, you'll see [Event Procedure] displayed in the list). Make sure the form itself is selected rather than the detail section or any control, they'll have their own associated events.

Double click the blank box next to the even name (OnOpen), and you should be taken to the VBA window with the cursor between the following:

CODE
Private Sub Form_Open(Cancel As Integer)

End Sub


This is where you'll put the code to tell it to go to a new record when the form is opened.

hth

So, this is what I modify the code to say?:

Private Sub Form_Open(Cancel As Integer)
Static MouseHook As Object
Set MouseHook = NewMouseHook(Me)
DoCmd.GoToRecord , , acNewRecord
End Sub



Instead of:


Private Sub Form_Open(Cancel As Integer)
Static MouseHook As Object
Set MouseHook = NewMouseHook(Me)

End Sub
gloworm
I went ahead and tried the modified code.

No go.
It didnt like it.

Got Comple Error. Variable not defined

acNewRecord is highlighted
gloworm
I got it to work.

Modified the statement to be:

DoCmd.RunCommand acCmdRecordsGoToNew

jleach
QUOTE (gloworm @ May 29 2012, 10:55 AM) *
I got it to work.

Modified the statement to be:

DoCmd.RunCommand acCmdRecordsGoToNew


That'll work also.

If you're curious about the other method, after you type DoCmd.GotoRecord and hit Space, Intellisense will come up with a description of the arguments... if there's a list of constants (such as acPrevious, acNext, acNewRecord, etc), you can select from the list. I probably missed a common so you were putting it in the wrong argument. Intellisense is of great help in determining what needs to go where, and even more help is putting the cursor in the keyword (GotoRecord) and hitting F1 for a complete description of what each argument does and what you're allowed to put there. Intellisense and Help are your two best friends when learning VBA.

Cheers,
gloworm
QUOTE (jleach @ May 29 2012, 10:51 AM) *
That'll work also.

If you're curious about the other method, after you type DoCmd.GotoRecord and hit Space, Intellisense will come up with a description of the arguments... if there's a list of constants (such as acPrevious, acNext, acNewRecord, etc), you can select from the list. I probably missed a common so you were putting it in the wrong argument. Intellisense is of great help in determining what needs to go where, and even more help is putting the cursor in the keyword (GotoRecord) and hitting F1 for a complete description of what each argument does and what you're allowed to put there. Intellisense and Help are your two best friends when learning VBA.

Cheers,


I tried this and couldnt get it to work.

When I get to the space after GoToRecord, I only have a few things to choose from in the drop down list.

acActiveDatObject
acDataForm
acDataFunction
acDataQuery
acDataReport
acDataServerView
acDataStoredProcedure
acDataTable


I dont have anything like acRecordNew.
jleach
Yes, that's the first argument, which is optional. From help:

QUOTE
ObjectType Optional AcDataObjectType.

AcDataObjectType can be one of these AcDataObjectType constants.
acActiveDataObject default
acDataForm
acDataFunction
acDataQuery
acDataServerView
acDataStoredProcedure
acDataTable

ObjectName Optional Variant. A string expression that's the valid name of an object of the type selected by the objecttype argument.

Record Optional AcRecord.

AcRecord can be one of these AcRecord constants.
acFirst
acGoTo
acLast
acNewRec
acNext default
acPrevious
If you leave this argument blank, the default constant (acNext) is assumed.


Thus, the following will work:

DoCmd.GotoRecord acDataForm, "MyForm", acNewRec

or...

DoCmd.GotoRecord , , acNewRec

or...

DoCmd.GotoRecord

or...

DoCmd.GotoRecord acDataForm

or...

DoCmd.GotoRecord , "MyForm"

as mentioned, highling "GotoRecord" and hitting F1 brings up the the help file which does a fairly good job outlining the requirements of the command.function.

hth
gloworm
QUOTE (jleach @ May 30 2012, 10:09 AM) *
Yes, that's the first argument, which is optional. From help:



Thus, the following will work:

DoCmd.GotoRecord acDataForm, "MyForm", acNewRec

or...

DoCmd.GotoRecord , , acNewRec

or...

DoCmd.GotoRecord

or...

DoCmd.GotoRecord acDataForm

or...

DoCmd.GotoRecord , "MyForm"

as mentioned, highling "GotoRecord" and hitting F1 brings up the the help file which does a fairly good job outlining the requirements of the command.function.

hth



I tried the help menu, but it want real helpful in explaining the various options.
Here is what my F1 brought up.
Click to view attachment
jleach
Yea, that's a typical help file. The layout and syntax of the VBA help has been the same for years... it's all there. If you have a few builtin functions that you are familiar with, check Help on those to get a feel for how Help tends to format the arguments. The top portion tells the syntax, the middle "table" portion gives detail info on each argument, and the Remarks section underneath tells how it acts under certain conditions, etc (ex: "If you leave the objecttype and objecname arguments blank, the active object is assumed"). In most cases they give an example at the very end.

You'll want to get familiar with it and learn how to read it... it can be a little confusing at first, but the built in Help really is your best tool for general day to day detail info on built in VBA functions.

Cheers,
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.