Hi all
I am very new to all of this, so I hope this is not a daft question. But I have hunted for a solution for a little more than a day so help would be appreciated.
My scenario is that I am using a one time table that is a copy of my real transaction table (called GLAcTranLine) to enter general ledger transactions. Both my form and my sub-form are unbound. The form is called GLFI50 and the sub form is called GLFI50TranSub on disk and inside the main form. That is, both the sub form and its description inside the form (in the label that appears when I build the sub form with the wizard) bear that name.
So in the load for the main form I carry out these job steps.
1. I take a "No Data" copy of the transaction table GLAcTranLine, to get the structure. That works fine. The name I give to it is prefaced with GLFI50 and ends with a random number. That works fine too.
2. I insert a blank record into the new table. That also works fine.
3. Assign the control source to the Sub form and to its individual objects.
That just dies in a crumpled heap. Neither the form not the individual columns code works.
The error I get (in both cases) is the Run-time error '2465' Application-defined or object-defined error.
I believe this means that it just cannot work out what idiotic error I have made. The code all passes the compiler test.
I am very new to Access-VBA and I do get massively confused by sub-form naming and behaviour. So I will welcome any input on my Syntax or anything else that anybody can spot.
Here is the SUB.
=================================================
Private Sub Form_Load()
'STEP 1. I take a "no data" copy of Create the Work Table and assign it as a control source to the sub form
'=======================================================================
'(Copies the structure of the source table to a new target one. It isn't a temporary table so I need to
'find a way of accigning a temporary name and then using that name on this prog.
'The True on the end says "Do not copy the data)"
'GLFI50Work is the Global variable that holds the temporary table name.
Dim RandomInt As Single
RandomInt = CInt((9999 - 1000 + 1) * Rnd() + 1000)
GLFI50Work = "GLFI50" & [RandomInt]
'DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentDb().Name, acTable, "GLAcTranLine", GLFI50Work, True
'Insert a blank record into the table
'-------------------------------------
'STEP 2 Insert a blank record
'============================2.
DoCmd.SetWarnings False
DoCmd.RunSQL _
"INSERT INTO " & GLFI50Work & _
" (AutoSeq, DRCR, DocRef, AccRef, LineDesc, Amount, STaxRate, STaxRateValue, AmountDocCurr, CostCentre)" & _
" VALUES (0, ' ', 0, ' ', ' ', 0, ' ',0,0,' ' )"
DoCmd.SetWarnings True
' STEP 3 Now assign the Control source to each column in the sub Form Transub
Dim SelString As String
SelString = "SELECT " & _
GLFI50Work & ".AutoSeq, " & _
GLFI50Work & ".DocRef, " & _
GLFI50Work & ".DrCR, " & _
GLFI50Work & ".AccRef, " & _
GLFI50Work & ".LineDesc, " & _
GLFI50Work & ".Amount, " & _
GLFI50Work & ".AmountDocCurr, " & _
GLFI50Work & ".STaxrate, " & _
GLFI50Work & ".STaxRateValue" & _
GLFI50Work & ".CostCentre, " & _
" FROM " & GLFI50Work & ";"
Me.[TranSub].Form.Control = SelString
' Now the individual objects
Me.[GLFI50TranSub].Form.AutoSeq.Control = AutoSeq
Me.[GLFI50TranSub].Form.Docref.Control = Docref
Me.[GLFI50TranSub].Form.DrCR.Control = DrCR
Me.[GLFI50TranSub].Form.AccRef.Control = AccRef
Me.[GLFI50TranSub].Form.LineDesc.Control = LineDesc
Me.[GLFI50TranSub].Form.Amount.Control = Amount
Me.[GLFI50TranSub].Form.AmountDocCurr.Control = AmountDocCurr
Me.[GLFI50TranSub].Form.STaxrate.Control = STaxrate
Me.[GLFI50TranSub].Form.STaxRateValue.Control = STaxRateValue
Me.[GLFI50TranSub].Form.CostCentre.Control = CostCentre
'Propose today's date.
'---------------------
Me.DocDate.Value = Date
End Sub
=================================================
I am very new to all of this, so I hope this is not a daft question. But I have hunted for a solution for a little more than a day so help would be appreciated.
My scenario is that I am using a one time table that is a copy of my real transaction table (called GLAcTranLine) to enter general ledger transactions. Both my form and my sub-form are unbound. The form is called GLFI50 and the sub form is called GLFI50TranSub on disk and inside the main form. That is, both the sub form and its description inside the form (in the label that appears when I build the sub form with the wizard) bear that name.
So in the load for the main form I carry out these job steps.
1. I take a "No Data" copy of the transaction table GLAcTranLine, to get the structure. That works fine. The name I give to it is prefaced with GLFI50 and ends with a random number. That works fine too.
2. I insert a blank record into the new table. That also works fine.
3. Assign the control source to the Sub form and to its individual objects.
That just dies in a crumpled heap. Neither the form not the individual columns code works.
The error I get (in both cases) is the Run-time error '2465' Application-defined or object-defined error.
I believe this means that it just cannot work out what idiotic error I have made. The code all passes the compiler test.
I am very new to Access-VBA and I do get massively confused by sub-form naming and behaviour. So I will welcome any input on my Syntax or anything else that anybody can spot.
Here is the SUB.
=================================================
Private Sub Form_Load()
'STEP 1. I take a "no data" copy of Create the Work Table and assign it as a control source to the sub form
'=======================================================================
'(Copies the structure of the source table to a new target one. It isn't a temporary table so I need to
'find a way of accigning a temporary name and then using that name on this prog.
'The True on the end says "Do not copy the data)"
'GLFI50Work is the Global variable that holds the temporary table name.
Dim RandomInt As Single
RandomInt = CInt((9999 - 1000 + 1) * Rnd() + 1000)
GLFI50Work = "GLFI50" & [RandomInt]
'DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentDb().Name, acTable, "GLAcTranLine", GLFI50Work, True
'Insert a blank record into the table
'-------------------------------------
'STEP 2 Insert a blank record
'============================2.
DoCmd.SetWarnings False
DoCmd.RunSQL _
"INSERT INTO " & GLFI50Work & _
" (AutoSeq, DRCR, DocRef, AccRef, LineDesc, Amount, STaxRate, STaxRateValue, AmountDocCurr, CostCentre)" & _
" VALUES (0, ' ', 0, ' ', ' ', 0, ' ',0,0,' ' )"
DoCmd.SetWarnings True
' STEP 3 Now assign the Control source to each column in the sub Form Transub
Dim SelString As String
SelString = "SELECT " & _
GLFI50Work & ".AutoSeq, " & _
GLFI50Work & ".DocRef, " & _
GLFI50Work & ".DrCR, " & _
GLFI50Work & ".AccRef, " & _
GLFI50Work & ".LineDesc, " & _
GLFI50Work & ".Amount, " & _
GLFI50Work & ".AmountDocCurr, " & _
GLFI50Work & ".STaxrate, " & _
GLFI50Work & ".STaxRateValue" & _
GLFI50Work & ".CostCentre, " & _
" FROM " & GLFI50Work & ";"
Me.[TranSub].Form.Control = SelString
' Now the individual objects
Me.[GLFI50TranSub].Form.AutoSeq.Control = AutoSeq
Me.[GLFI50TranSub].Form.Docref.Control = Docref
Me.[GLFI50TranSub].Form.DrCR.Control = DrCR
Me.[GLFI50TranSub].Form.AccRef.Control = AccRef
Me.[GLFI50TranSub].Form.LineDesc.Control = LineDesc
Me.[GLFI50TranSub].Form.Amount.Control = Amount
Me.[GLFI50TranSub].Form.AmountDocCurr.Control = AmountDocCurr
Me.[GLFI50TranSub].Form.STaxrate.Control = STaxrate
Me.[GLFI50TranSub].Form.STaxRateValue.Control = STaxRateValue
Me.[GLFI50TranSub].Form.CostCentre.Control = CostCentre
'Propose today's date.
'---------------------
Me.DocDate.Value = Date
End Sub
=================================================