PC Review


Reply
Thread Tools Rate Thread

Adding records to subform

 
 
Zedbiker
Guest
Posts: n/a
 
      8th Jun 2009
Hi
My parent form (backpackorder)takes information from a table which lists the
parts used in an asembly. Each part is linked to a subform by its part id
(backpackpartid). The subform contains the order information. When I press a
button on the main form I want to automatically order all the parts. I have
tried to do this using the code below (probably not best way but it sort of
works. Never professed to being a programmer :-) ). It runs through the first
part ok adding the record automatically, then goes to the next part and stops
at the first record.
What am I doing wrong? Msgbox's have been added for error trapping. Many
thanks for any help.

Private Sub CmdOrder_Click()
On Error GoTo Err_CmdOrder_Click

Dim BatchNo As String
Dim ComponentName As String
Dim Priority As String
Dim Signature As String
Dim Quantity As Integer
Dim i As Integer
Dim IDno, IDinc As Integer

DoCmd.GoToRecord , , acLast
IDno = Me![BackPackPartID].Value
MsgBox (IDno)
DoCmd.GoToRecord , , acFirst
IDinc = 1
If IDinc <= IDno Then
IDinc = Me![BackPackPartID].Value
MsgBox (IDinc)
Me![BackPackSubform].SetFocus
DoCmd.GoToRecord , , acLast
BatchNo = Me![BackPackSubform]![Batch]
ComponentName = Me![Component Name]
Quantity = Me![BackPackSubform]![Quantity]

If Me![BackPackPartID] = "1" Then
Signature = Me![CmbSignature].Column(1)
Priority = Me![CmbPriorityLevel].Column(0)
End If

i = CInt(BatchNo)
MsgBox (i)
i = i + 1
BatchNo = CStr(i)
MsgBox (BatchNo)
BatchNo = Format([BatchNo], "000")
MsgBox (BatchNo)

DoCmd.GoToRecord , , acNewRec
Me![BackPackSubform]![Batch] = BatchNo
Me![BackPackSubform]![Component Name] = ComponentName
Me![BackPackSubform]![Signature] = Signature
Me![BackPackSubform]![Priority] = Priority
Me![BackPackSubform]![Quantity] = Quantity
IDinc = IDinc + 1
MsgBox (IDinc)
DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
MsgBox ("Continue?")

End If

Exit_CmdOrder_Click:
Exit Sub
Err_CmdOrder_Click:
MsgBox Err.Description
Resume Exit_CmdOrder_Click

End Sub

 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      9th Jun 2009
Hi,
try to write an append (insert) query instead, as I see - it easy solve you
problem. And requery subform after you run it

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Zedbiker" <(E-Mail Removed)> wrote in message
news160B96D-4D90-4136-A508-(E-Mail Removed)...
> Hi
> My parent form (backpackorder)takes information from a table which lists
> the
> parts used in an asembly. Each part is linked to a subform by its part id
> (backpackpartid). The subform contains the order information. When I press
> a
> button on the main form I want to automatically order all the parts. I
> have
> tried to do this using the code below (probably not best way but it sort
> of
> works. Never professed to being a programmer :-) ). It runs through the
> first
> part ok adding the record automatically, then goes to the next part and
> stops
> at the first record.
> What am I doing wrong? Msgbox's have been added for error trapping. Many
> thanks for any help.
>
> Private Sub CmdOrder_Click()
> On Error GoTo Err_CmdOrder_Click
>
> Dim BatchNo As String
> Dim ComponentName As String
> Dim Priority As String
> Dim Signature As String
> Dim Quantity As Integer
> Dim i As Integer
> Dim IDno, IDinc As Integer
>
> DoCmd.GoToRecord , , acLast
> IDno = Me![BackPackPartID].Value
> MsgBox (IDno)
> DoCmd.GoToRecord , , acFirst
> IDinc = 1
> If IDinc <= IDno Then
> IDinc = Me![BackPackPartID].Value
> MsgBox (IDinc)
> Me![BackPackSubform].SetFocus
> DoCmd.GoToRecord , , acLast
> BatchNo = Me![BackPackSubform]![Batch]
> ComponentName = Me![Component Name]
> Quantity = Me![BackPackSubform]![Quantity]
>
> If Me![BackPackPartID] = "1" Then
> Signature = Me![CmbSignature].Column(1)
> Priority = Me![CmbPriorityLevel].Column(0)
> End If
>
> i = CInt(BatchNo)
> MsgBox (i)
> i = i + 1
> BatchNo = CStr(i)
> MsgBox (BatchNo)
> BatchNo = Format([BatchNo], "000")
> MsgBox (BatchNo)
>
> DoCmd.GoToRecord , , acNewRec
> Me![BackPackSubform]![Batch] = BatchNo
> Me![BackPackSubform]![Component Name] = ComponentName
> Me![BackPackSubform]![Signature] = Signature
> Me![BackPackSubform]![Priority] = Priority
> Me![BackPackSubform]![Quantity] = Quantity
> IDinc = IDinc + 1
> MsgBox (IDinc)
> DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
> MsgBox ("Continue?")
>
> End If
>
> Exit_CmdOrder_Click:
> Exit Sub
> Err_CmdOrder_Click:
> MsgBox Err.Description
> Resume Exit_CmdOrder_Click
>
> End Sub
>

 
Reply With Quote
 
Zedbiker
Guest
Posts: n/a
 
      9th Jun 2009
Hi Alex
Thank you for your reply. Excuse my ignorance. Do you mean that I should add
this into my VBA. I have not used an append query before so this again is new
ground for me. Can you suggest a tutorial website that can give me more
advice to save your time.
This database started as a basic ordering database and as it has progressed
colleagues have asked for more and more additions which has meant a steep
learning curve for me. I hope this explains my ignorance.
Thank you again for any help you can offer.
Best Regards
Ian
P.S. This is my 4th or 5th attempt at replying to you. This website keeps
crashing and I lose my reply. Very frustrating!!


"Alex Dybenko" wrote:

> Hi,
> try to write an append (insert) query instead, as I see - it easy solve you
> problem. And requery subform after you run it
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
>
> "Zedbiker" <(E-Mail Removed)> wrote in message
> news160B96D-4D90-4136-A508-(E-Mail Removed)...
> > Hi
> > My parent form (backpackorder)takes information from a table which lists
> > the
> > parts used in an asembly. Each part is linked to a subform by its part id
> > (backpackpartid). The subform contains the order information. When I press
> > a
> > button on the main form I want to automatically order all the parts. I
> > have
> > tried to do this using the code below (probably not best way but it sort
> > of
> > works. Never professed to being a programmer :-) ). It runs through the
> > first
> > part ok adding the record automatically, then goes to the next part and
> > stops
> > at the first record.
> > What am I doing wrong? Msgbox's have been added for error trapping. Many
> > thanks for any help.
> >
> > Private Sub CmdOrder_Click()
> > On Error GoTo Err_CmdOrder_Click
> >
> > Dim BatchNo As String
> > Dim ComponentName As String
> > Dim Priority As String
> > Dim Signature As String
> > Dim Quantity As Integer
> > Dim i As Integer
> > Dim IDno, IDinc As Integer
> >
> > DoCmd.GoToRecord , , acLast
> > IDno = Me![BackPackPartID].Value
> > MsgBox (IDno)
> > DoCmd.GoToRecord , , acFirst
> > IDinc = 1
> > If IDinc <= IDno Then
> > IDinc = Me![BackPackPartID].Value
> > MsgBox (IDinc)
> > Me![BackPackSubform].SetFocus
> > DoCmd.GoToRecord , , acLast
> > BatchNo = Me![BackPackSubform]![Batch]
> > ComponentName = Me![Component Name]
> > Quantity = Me![BackPackSubform]![Quantity]
> >
> > If Me![BackPackPartID] = "1" Then
> > Signature = Me![CmbSignature].Column(1)
> > Priority = Me![CmbPriorityLevel].Column(0)
> > End If
> >
> > i = CInt(BatchNo)
> > MsgBox (i)
> > i = i + 1
> > BatchNo = CStr(i)
> > MsgBox (BatchNo)
> > BatchNo = Format([BatchNo], "000")
> > MsgBox (BatchNo)
> >
> > DoCmd.GoToRecord , , acNewRec
> > Me![BackPackSubform]![Batch] = BatchNo
> > Me![BackPackSubform]![Component Name] = ComponentName
> > Me![BackPackSubform]![Signature] = Signature
> > Me![BackPackSubform]![Priority] = Priority
> > Me![BackPackSubform]![Quantity] = Quantity
> > IDinc = IDinc + 1
> > MsgBox (IDinc)
> > DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
> > MsgBox ("Continue?")
> >
> > End If
> >
> > Exit_CmdOrder_Click:
> > Exit Sub
> > Err_CmdOrder_Click:
> > MsgBox Err.Description
> > Resume Exit_CmdOrder_Click
> >
> > End Sub
> >

>

 
Reply With Quote
 
Zedbiker
Guest
Posts: n/a
 
      9th Jun 2009
Hi again
I changed my If statement to a 'Do While...'. This allowed my program to
work although I am sure the way you suggested would be better and less
clumsy.
Thank you
Ian

"Zedbiker" wrote:

> Hi Alex
> Thank you for your reply. Excuse my ignorance. Do you mean that I should add
> this into my VBA. I have not used an append query before so this again is new
> ground for me. Can you suggest a tutorial website that can give me more
> advice to save your time.
> This database started as a basic ordering database and as it has progressed
> colleagues have asked for more and more additions which has meant a steep
> learning curve for me. I hope this explains my ignorance.
> Thank you again for any help you can offer.
> Best Regards
> Ian
> P.S. This is my 4th or 5th attempt at replying to you. This website keeps
> crashing and I lose my reply. Very frustrating!!
>
>
> "Alex Dybenko" wrote:
>
> > Hi,
> > try to write an append (insert) query instead, as I see - it easy solve you
> > problem. And requery subform after you run it
> >
> > --
> > Best regards,
> > ___________
> > Alex Dybenko (MVP)
> > http://accessblog.net
> > http://www.PointLtd.com
> >
> >
> > "Zedbiker" <(E-Mail Removed)> wrote in message
> > news160B96D-4D90-4136-A508-(E-Mail Removed)...
> > > Hi
> > > My parent form (backpackorder)takes information from a table which lists
> > > the
> > > parts used in an asembly. Each part is linked to a subform by its part id
> > > (backpackpartid). The subform contains the order information. When I press
> > > a
> > > button on the main form I want to automatically order all the parts. I
> > > have
> > > tried to do this using the code below (probably not best way but it sort
> > > of
> > > works. Never professed to being a programmer :-) ). It runs through the
> > > first
> > > part ok adding the record automatically, then goes to the next part and
> > > stops
> > > at the first record.
> > > What am I doing wrong? Msgbox's have been added for error trapping. Many
> > > thanks for any help.
> > >
> > > Private Sub CmdOrder_Click()
> > > On Error GoTo Err_CmdOrder_Click
> > >
> > > Dim BatchNo As String
> > > Dim ComponentName As String
> > > Dim Priority As String
> > > Dim Signature As String
> > > Dim Quantity As Integer
> > > Dim i As Integer
> > > Dim IDno, IDinc As Integer
> > >
> > > DoCmd.GoToRecord , , acLast
> > > IDno = Me![BackPackPartID].Value
> > > MsgBox (IDno)
> > > DoCmd.GoToRecord , , acFirst
> > > IDinc = 1
> > > If IDinc <= IDno Then
> > > IDinc = Me![BackPackPartID].Value
> > > MsgBox (IDinc)
> > > Me![BackPackSubform].SetFocus
> > > DoCmd.GoToRecord , , acLast
> > > BatchNo = Me![BackPackSubform]![Batch]
> > > ComponentName = Me![Component Name]
> > > Quantity = Me![BackPackSubform]![Quantity]
> > >
> > > If Me![BackPackPartID] = "1" Then
> > > Signature = Me![CmbSignature].Column(1)
> > > Priority = Me![CmbPriorityLevel].Column(0)
> > > End If
> > >
> > > i = CInt(BatchNo)
> > > MsgBox (i)
> > > i = i + 1
> > > BatchNo = CStr(i)
> > > MsgBox (BatchNo)
> > > BatchNo = Format([BatchNo], "000")
> > > MsgBox (BatchNo)
> > >
> > > DoCmd.GoToRecord , , acNewRec
> > > Me![BackPackSubform]![Batch] = BatchNo
> > > Me![BackPackSubform]![Component Name] = ComponentName
> > > Me![BackPackSubform]![Signature] = Signature
> > > Me![BackPackSubform]![Priority] = Priority
> > > Me![BackPackSubform]![Quantity] = Quantity
> > > IDinc = IDinc + 1
> > > MsgBox (IDinc)
> > > DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
> > > MsgBox ("Continue?")
> > >
> > > End If
> > >
> > > Exit_CmdOrder_Click:
> > > Exit Sub
> > > Err_CmdOrder_Click:
> > > MsgBox Err.Description
> > > Resume Exit_CmdOrder_Click
> > >
> > > End Sub
> > >

> >

 
Reply With Quote
 
Alex Dybenko
Guest
Posts: n/a
 
      9th Jun 2009
Hi,
I think best would be to read some book on Access, if you have one, else -
try to google for building access queries
If you get the idea how it works - you can then easy compete such tasks,
queries - is most powerful feature of Access


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"Zedbiker" <(E-Mail Removed)> wrote in message
news:E9FE9A53-79D3-40AE-889F-(E-Mail Removed)...
> Hi Alex
> Thank you for your reply. Excuse my ignorance. Do you mean that I should
> add
> this into my VBA. I have not used an append query before so this again is
> new
> ground for me. Can you suggest a tutorial website that can give me more
> advice to save your time.
> This database started as a basic ordering database and as it has
> progressed
> colleagues have asked for more and more additions which has meant a steep
> learning curve for me. I hope this explains my ignorance.
> Thank you again for any help you can offer.
> Best Regards
> Ian
> P.S. This is my 4th or 5th attempt at replying to you. This website keeps
> crashing and I lose my reply. Very frustrating!!
>
>
> "Alex Dybenko" wrote:
>
>> Hi,
>> try to write an append (insert) query instead, as I see - it easy solve
>> you
>> problem. And requery subform after you run it
>>
>> --
>> Best regards,
>> ___________
>> Alex Dybenko (MVP)
>> http://accessblog.net
>> http://www.PointLtd.com
>>
>>
>> "Zedbiker" <(E-Mail Removed)> wrote in message
>> news160B96D-4D90-4136-A508-(E-Mail Removed)...
>> > Hi
>> > My parent form (backpackorder)takes information from a table which
>> > lists
>> > the
>> > parts used in an asembly. Each part is linked to a subform by its part
>> > id
>> > (backpackpartid). The subform contains the order information. When I
>> > press
>> > a
>> > button on the main form I want to automatically order all the parts. I
>> > have
>> > tried to do this using the code below (probably not best way but it
>> > sort
>> > of
>> > works. Never professed to being a programmer :-) ). It runs through the
>> > first
>> > part ok adding the record automatically, then goes to the next part and
>> > stops
>> > at the first record.
>> > What am I doing wrong? Msgbox's have been added for error trapping.
>> > Many
>> > thanks for any help.
>> >
>> > Private Sub CmdOrder_Click()
>> > On Error GoTo Err_CmdOrder_Click
>> >
>> > Dim BatchNo As String
>> > Dim ComponentName As String
>> > Dim Priority As String
>> > Dim Signature As String
>> > Dim Quantity As Integer
>> > Dim i As Integer
>> > Dim IDno, IDinc As Integer
>> >
>> > DoCmd.GoToRecord , , acLast
>> > IDno = Me![BackPackPartID].Value
>> > MsgBox (IDno)
>> > DoCmd.GoToRecord , , acFirst
>> > IDinc = 1
>> > If IDinc <= IDno Then
>> > IDinc = Me![BackPackPartID].Value
>> > MsgBox (IDinc)
>> > Me![BackPackSubform].SetFocus
>> > DoCmd.GoToRecord , , acLast
>> > BatchNo = Me![BackPackSubform]![Batch]
>> > ComponentName = Me![Component Name]
>> > Quantity = Me![BackPackSubform]![Quantity]
>> >
>> > If Me![BackPackPartID] = "1" Then
>> > Signature = Me![CmbSignature].Column(1)
>> > Priority = Me![CmbPriorityLevel].Column(0)
>> > End If
>> >
>> > i = CInt(BatchNo)
>> > MsgBox (i)
>> > i = i + 1
>> > BatchNo = CStr(i)
>> > MsgBox (BatchNo)
>> > BatchNo = Format([BatchNo], "000")
>> > MsgBox (BatchNo)
>> >
>> > DoCmd.GoToRecord , , acNewRec
>> > Me![BackPackSubform]![Batch] = BatchNo
>> > Me![BackPackSubform]![Component Name] = ComponentName
>> > Me![BackPackSubform]![Signature] = Signature
>> > Me![BackPackSubform]![Priority] = Priority
>> > Me![BackPackSubform]![Quantity] = Quantity
>> > IDinc = IDinc + 1
>> > MsgBox (IDinc)
>> > DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
>> > MsgBox ("Continue?")
>> >
>> > End If
>> >
>> > Exit_CmdOrder_Click:
>> > Exit Sub
>> > Err_CmdOrder_Click:
>> > MsgBox Err.Description
>> > Resume Exit_CmdOrder_Click
>> >
>> > End Sub
>> >

>>

 
Reply With Quote
 
Zedbiker
Guest
Posts: n/a
 
      9th Jun 2009
Thank you for your patience. I will certainly do some reading about queries.
Up to now I think I have just touched on the surface of what they can do.
Thank you again for your advice.
Ian

"Alex Dybenko" wrote:

> Hi,
> I think best would be to read some book on Access, if you have one, else -
> try to google for building access queries
> If you get the idea how it works - you can then easy compete such tasks,
> queries - is most powerful feature of Access
>
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
> "Zedbiker" <(E-Mail Removed)> wrote in message
> news:E9FE9A53-79D3-40AE-889F-(E-Mail Removed)...
> > Hi Alex
> > Thank you for your reply. Excuse my ignorance. Do you mean that I should
> > add
> > this into my VBA. I have not used an append query before so this again is
> > new
> > ground for me. Can you suggest a tutorial website that can give me more
> > advice to save your time.
> > This database started as a basic ordering database and as it has
> > progressed
> > colleagues have asked for more and more additions which has meant a steep
> > learning curve for me. I hope this explains my ignorance.
> > Thank you again for any help you can offer.
> > Best Regards
> > Ian
> > P.S. This is my 4th or 5th attempt at replying to you. This website keeps
> > crashing and I lose my reply. Very frustrating!!
> >
> >
> > "Alex Dybenko" wrote:
> >
> >> Hi,
> >> try to write an append (insert) query instead, as I see - it easy solve
> >> you
> >> problem. And requery subform after you run it
> >>
> >> --
> >> Best regards,
> >> ___________
> >> Alex Dybenko (MVP)
> >> http://accessblog.net
> >> http://www.PointLtd.com
> >>
> >>
> >> "Zedbiker" <(E-Mail Removed)> wrote in message
> >> news160B96D-4D90-4136-A508-(E-Mail Removed)...
> >> > Hi
> >> > My parent form (backpackorder)takes information from a table which
> >> > lists
> >> > the
> >> > parts used in an asembly. Each part is linked to a subform by its part
> >> > id
> >> > (backpackpartid). The subform contains the order information. When I
> >> > press
> >> > a
> >> > button on the main form I want to automatically order all the parts. I
> >> > have
> >> > tried to do this using the code below (probably not best way but it
> >> > sort
> >> > of
> >> > works. Never professed to being a programmer :-) ). It runs through the
> >> > first
> >> > part ok adding the record automatically, then goes to the next part and
> >> > stops
> >> > at the first record.
> >> > What am I doing wrong? Msgbox's have been added for error trapping.
> >> > Many
> >> > thanks for any help.
> >> >
> >> > Private Sub CmdOrder_Click()
> >> > On Error GoTo Err_CmdOrder_Click
> >> >
> >> > Dim BatchNo As String
> >> > Dim ComponentName As String
> >> > Dim Priority As String
> >> > Dim Signature As String
> >> > Dim Quantity As Integer
> >> > Dim i As Integer
> >> > Dim IDno, IDinc As Integer
> >> >
> >> > DoCmd.GoToRecord , , acLast
> >> > IDno = Me![BackPackPartID].Value
> >> > MsgBox (IDno)
> >> > DoCmd.GoToRecord , , acFirst
> >> > IDinc = 1
> >> > If IDinc <= IDno Then
> >> > IDinc = Me![BackPackPartID].Value
> >> > MsgBox (IDinc)
> >> > Me![BackPackSubform].SetFocus
> >> > DoCmd.GoToRecord , , acLast
> >> > BatchNo = Me![BackPackSubform]![Batch]
> >> > ComponentName = Me![Component Name]
> >> > Quantity = Me![BackPackSubform]![Quantity]
> >> >
> >> > If Me![BackPackPartID] = "1" Then
> >> > Signature = Me![CmbSignature].Column(1)
> >> > Priority = Me![CmbPriorityLevel].Column(0)
> >> > End If
> >> >
> >> > i = CInt(BatchNo)
> >> > MsgBox (i)
> >> > i = i + 1
> >> > BatchNo = CStr(i)
> >> > MsgBox (BatchNo)
> >> > BatchNo = Format([BatchNo], "000")
> >> > MsgBox (BatchNo)
> >> >
> >> > DoCmd.GoToRecord , , acNewRec
> >> > Me![BackPackSubform]![Batch] = BatchNo
> >> > Me![BackPackSubform]![Component Name] = ComponentName
> >> > Me![BackPackSubform]![Signature] = Signature
> >> > Me![BackPackSubform]![Priority] = Priority
> >> > Me![BackPackSubform]![Quantity] = Quantity
> >> > IDinc = IDinc + 1
> >> > MsgBox (IDinc)
> >> > DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
> >> > MsgBox ("Continue?")
> >> >
> >> > End If
> >> >
> >> > Exit_CmdOrder_Click:
> >> > Exit Sub
> >> > Err_CmdOrder_Click:
> >> > MsgBox Err.Description
> >> > Resume Exit_CmdOrder_Click
> >> >
> >> > End Sub
> >> >
> >>

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Adding new records using subform? John Vinson Microsoft Access Form Coding 0 23rd Dec 2005 07:34 PM
Adding new records on a subform =?Utf-8?B?SmltIFNjYXJsZXR0?= Microsoft Access Form Coding 0 28th Apr 2005 02:36 PM
Adding new records to a subform Meagan Microsoft Access 1 20th Oct 2004 07:59 PM
Adding records in Subform Pat Microsoft Access Form Coding 1 15th Jun 2004 08:46 AM
Adding new records in subform for all main records =?Utf-8?B?TWljaGVsZQ==?= Microsoft Access Forms 1 26th Apr 2004 04:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 AM.