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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DefaultValue to New Record Not Working

Status
Not open for further replies.

IJOC

Technical User
Jan 27, 2009
24
US
I have used this code before to populate a new record with a previous records value. This time it is not working. The only difference is the previous time it was on a continuous form and this on is a single form. Can someone point me in the right direction. Thanks again -Pat


Private Sub cmdSaveandNew_Click()
On Error GoTo Err_cmdSaveandNew_Click


DoCmd.GoToRecord , , acNewRec

Exit_cmdSaveandNew_Click:
Exit Sub

Err_cmdSaveandNew_Click:
MsgBox Err.Description
Resume Exit_cmdSaveandNew_Click
End Sub

Private Sub fkSetID_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.fkSetID.Value) Then
fkSetID.DefaultValue = """" & Me.fkSetID.Value & """"
End If
End Sub
 
Yes I am updating the control of fkSetID. So basically I have a form that has set and a subform that has cards that belong to the set. I click on a card number and it opens the form in question in which the first field is fkSetID. I have a Save & New button (cmdSaveandNew)that I click on and it opens a new record but does not populate fkSetID. I don't want the user to have to manually type or select the set because it is to error prone. I hope the makes sense.

In the previous form that I used this on it was a continuous form and I tabbed into a new record. This one is a single form the is a pop/modal form. I tried with out popup and modal that did not seem to make a difference.

Thanks for your help.
 
I don't understand. It sounds like you are opening a different form and are not keying in a new value into the fkSetID in the form where you want a default value.

Duane
Hook'D on Access
MS Access MVP
 
I have even tried this and it is not working

Private Sub fkSetID_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.fkSetID.Value) Then
Forms![mfrmSets]![pkSetID].DefaultValue = """" & Me.fkSetID.Value & """"
End If
End Sub
 
Why are posters so consistent with "it is not working" without providing any details about what might be happening or not.

Why are you using a before update event? If you are truly opening a new form and want to set a default in the new form, you might want to pass the default value in the OpenArgs.

Duane
Hook'D on Access
MS Access MVP
 
Sorry that I was not more detailed in my first post. I am really a newbie to vb and am trying my best to learn. I try to use snippets of what has worked in the past and incorporate that into what I am doing. The Before Update is what I used in past and it worked.

I don't have a clear understanding of the OpenArgs, but will search and try to learn more about it. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top