Anything behind the "New" record button?
Anything behind the "New" record button?
Do me a favor and convert the macro to code so I can work on it for you and post it here. http://www.btabdevelopment.com/ts/de...aspx?PageId=91
The only home made macro running on the form is to insert the date (see below). Record save and goto new record are built in onesDo me a favor and convert the macro to code so I can work on it for you and post it here. http://www.btabdevelopment.com/ts/de...aspx?PageId=91
Option Compare Database
'------------------------------------------------------------
' Date_out
'
'------------------------------------------------------------
Function Date_out()
On Error GoTo Date_out_Err
With CodeContextObject
.[Month out] = Date
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
End With
Date_out_Exit:
Exit Function
Date_out_Err:
MsgBox Error$
Resume Date_out_Exit
End Function
regards
Pete
Try this code instead of what you have and see what happens:
Code:Option Compare Database Option Explicit'------------------------------------------------------------ ' Date_out ' '------------------------------------------------------------ Function Date_out() On Error GoTo Date_out_Err CodeContextObject.[Month out] = Date Const cQuote = """" 'Thats two quotes Me.[Loaned to].DefaultValue = cQuote & Me.[Loaned to].Value & cQuote DoCmd.RunCommand acCmdSaveRecord DoCmd.RunCommand acCmdRecordsGoToNew Date_out_Exit: Exit Function Date_out_Err: MsgBox Error$ Resume Date_out_Exit End Function
The button (command 45) on click code now reads as pasted below but brings up "compile error - invalid inside procedure"
Any thoughts?
regards and thank you for helping
Pete
Private Sub Command45_Click()
Option Compare Database
Option Explicit '------------------------------------------------------------
' Date_out
'
'------------------------------------------------------------
Function Date_out()
On Error GoTo Date_out_Err
CodeContextObject.[Month out] = Date
Const cQuote = """" 'Thats two quotes
Me.[Loaned to].DefaultValue = cQuote & Me.[Loaned to].Value & cQuote
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
Date_out_Exit:
Exit Function
Date_out_Err:
MsgBox Error$
Resume Date_out_Exit
End Function
End Function
UPDATE
I realised my error and saved the code below separately as a function called by the button click event. I also changed Date_out to Date_lent as there seemed to be an ambiguous conflict.
This gave rise to a different error where ' .DefaultValue = ' was highlighted "; method or data member not found.
Hope this helps
regards
Pete
Public Function Date_lent()
On Error GoTo Date_lent_Err
CodeContextObject.[Month out] = Date
Const cQuote = """"
Me.[Loaned to].DefaultValue = cQuote & Me.[Loaned to].Value & cQuote
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
Date_lent_Exit:
Exit Function
Date_lent_Err:
MsgBox Error$
Resume Date_lent_Exit
End Function
Last edited by parishpete; 11-01-2012 at 03:10 PM. Reason: updated info
Type this line by hand:
Me.[Loaned to].DefaultValue = cQuote & Me.[Loaned to].Value & cQuote
...when you hit the "." after Me the intellisense should kick in and show you all of the possible values at this point. Select the correct on and enter another ".". Once again the intellisense should show you the valid possibilities. Is DefaultValue there?
No. Only Value is there following [Loaned to]Type this line by hand:
Me.[Loaned to].DefaultValue = cQuote & Me.[Loaned to].Value & cQuote
...when you hit the "." after Me the intellisense should kick in and show you all of the possible values at this point. Select the correct on and enter another ".". Once again the intellisense should show you the valid possibilities. Is DefaultValue there?
regards
Pete
Hmm...what type of control is this?
It's an event procedure against on click which runs a subroutine which in turn calls the function you provided.
I am running 2010 with auto update.
Should I be handling this differently? It seemed straightforward at the time.
regards
Pete
As a further thought, having saved the first record, could I pull the field value for [loanedto] from the loan table and put it back into a new record on the form? That record entry will have the highest unique ID number.
Last edited by parishpete; 11-02-2012 at 03:21 AM. Reason: further thought
UPDATED
I'm virtually done thanks to your help. I certainly would have given up without it
The code below uses a variable [Borrower] ( i used a temporary textbox on the form just to show the value of [Loaned to] at any given time).
The code below assigns a default value to [Borrower] which changes each time the button is pressed and passes the value to [Loaned to]. This handles multiple entries perfectly.
I have also set up a second button to handle single entries.
The only thing that needs tidying is error handling in the code below. Because [Loaned to] has an entry and a value in a new record after the button is pressed, I cannot exit the form properly if I press that button last by mistake.
Would welcome your view at your leisure
regards
Pete
Public Function Date_lent()
On Error GoTo Date_lent_Err
CodeContextObject.[Month out] = Date
DoCmd.RunCommand acCmdSaveRecord
Me.[Borrower].DefaultValue = Me.[Loaned to].Value
DoCmd.RunCommand acCmdRecordsGoToNew
Me.[Loaned to].Value = [Borrower]
Date_lent_Exit:
Exit Function
Date_lent_Err:
MsgBox Error$
Resume Date_lent_Exit
End Function
Last edited by parishpete; 11-02-2012 at 03:28 PM. Reason: Updated information
I'm working on another problem right now and will get back to this one when finished, Okay?
I'm one of those guys that thinks a programmer should spend hundreds of hours to save a user a second. I'm not a big fan of a bunch of buttons to choose from if there is a way to make things happen automatically. I think you could eliminate some of these buttons by putting some code in some of the events that occur.
Default values do *not* Dirty a record so setting it would not cause the problem you are describing. You are aware that *all* Dirty records are always saved by simply trying to leave the record in any fashion, right?