Form / Table help

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
I have a form where the user scans his ID and then a work order bar code which files in order number, item number and op number, he then enters with the keypad, good pcs, scrap pcs, selects a scrap reason code from a combo box and then selects the time the job was started. It also will add the current time, date and total time to the table automatically. My question is the person may have 5 scrap pcs for one reason and 1 scrap for another reason and so on, how can I make it so they would just have to enter the second scrap reason and pcs and not have to go through the whole for again? If I type it in now without scanning the other information it will leave blank cells in the table and will not be linked to the order, empl or item numbers. Would this be where I would use a subform?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Are you essentially saying that you want to copy all the info and create a new record? If so, I have done that before via a "Copy This to New Record" button on my form, with the following VBA running in the On Click event:
Code:
a = MsgBox("Do you really want to copy this record to another semester? Doing so will mark this record as 'Inactive'. You will also need to supply some of the fields that will not transfer.", vbYesNo)
If a = vbYes Then
    Me!archiveGroup.Value = True
    varStudyTitle = Me!studyTitle.Value
    varGroupDescription = Me!groupDescription.Value
    varMeetingLocation = Me!meetingLocation.Value
    varMeetingDay = Me!meetingDay.Value
    varMeetingTime = Me!meetingTime.Value
    
    RunCommand acCmdRecordsGoToNew
    
    Me!studyTitle = varStudyTitle
    Me!groupDescription = varGroupDescription
    Me!meetingLocation = varMeetingLocation
    Me!meetingDay = varMeetingDay
    Me!meetingTime = varMeetingTime
    MsgBox ("You have copied this record. Please supply the 'Semester', 'Leader', and 'First Meeting' fields.")
    DoCmd.GoToControl ("studyTitle")
End If
Of course, change the variable to your liking and the controls to what you have on your form already. The
Code:
RunCommand acCmdRecordsGoToNew
will take you to a new record where the second half of the code essentially "pastes" the info to the new record.
 
Upvote 0
Oh, and ignore some of that other stuff. I thought I cleaned it up. Sorry!
Code:
a = MsgBox("Do you really want to copy this record to another semester?, vbYesNo)
If a = vbYes Then
    varStudyTitle = Me!studyTitle.Value
    varGroupDescription = Me!groupDescription.Value
    varMeetingLocation = Me!meetingLocation.Value
    varMeetingDay = Me!meetingDay.Value
    varMeetingTime = Me!meetingTime.Value
    
    RunCommand acCmdRecordsGoToNew
    
    Me!studyTitle = varStudyTitle
    Me!groupDescription = varGroupDescription
    Me!meetingLocation = varMeetingLocation
    Me!meetingDay = varMeetingDay
    Me!meetingTime = varMeetingTime
    MsgBox ("You have copied this record.")
    DoCmd.GoToControl ("studyTitle")
End If
 
Upvote 0
Montez659,

I am not sure if I am doing this correctly, the info does go into the table when I run the code but it leaves blank cells. Let me see if I can explain the user form a little better

First text box
Control- EmployeeNumber
Employee scans badge

Second, third and fourth text boxes
Control - ItemNumber
Control - ShopOrderNumber
Control - OpNumber
the employee scans a barcode and there is some code that splits it into the 3 text boxes

Fifth text box
Control - GoodPcs
Employee enters with keypad

Sixth text box
Control - ScrapPcs
Employee enters with key pad

Seventh combo box
Control - ScrapReason
Employee selects reason code from drop down box

Eighth combo box
Control - StartTime
Employee selects the time they started the job

ninth text box
Control - StopTime
Default value = Time()

Last text box
Control - Date
Default value =Date()

The form works fine as the employee scans or enters data for each box, but an example where I need help and they are asking me to change it is in this situation, an employee may run for 8 hours and have 1000 good parts, they may have 20 scrap parts, 5 for reason 1, 5 for reason 2 and 10 for reason 3 and so on. When they enter the data into the form the do as above but only can enter one reason code in with that pass, they want to enter the other 2 reason codes in with out having to scan their badge and order form all over again. So what I need to happen is for them to only have to enter the scrap quantity and select the reason code on the second and third pass. In the table I need the fields EmployeeNumber, ItemNumber, ShopOrderNumber, OpNumber, and date to be matched up with the same data that was entered on the first pass, I don't need good, starttime or stoptime they can be left blank in this row of the table. i tried your code and it enters but it does not seem to be doing what I need, here is how I changed it.
Code:
Private Sub Command46_Click()
a = MsgBox("Do you want to enter extra scrap codes?", vbYesNo)
If a = vbYes Then
    
    varEmployeeNumber = Me!EmployeeNumber.Value
    varItemNumber = Me!ItemNumber.Value
    varShopOrderNumber = Me!ShoporderNumber.Value
    varOpNumber = Me!OpNumber.Value
   
    
    RunCommand acCmdRecordsGoToNew
    
    Me!Employee_Number = varEmployee_Number
    Me!ItemNumber.Value = varItemNumber
    Me!ShoporderNumber.Value = varShopOrderNumber
    varOp_Number = Me!OpNumber.Value
    MsgBox ("Thank You")
    
End If
End Sub
 
Upvote 0
Let me ask this question before I proceed: were you wanting a new record each time? As in, aside from some of the fields not populating correctly, is this kind of what you were looking for?

I caught two errors in your code as well. The first is varaible varOpNumber. When you are trying to get this variable to output to the textbox, you put
Code:
varOp_Number = Me!OpNumber.Value
This should be
Code:
 Me!OpNumber.Value = varOpNumber

Secondly, varEmployeeNumber is not the same as varEmployee_Number, so change these to match.

See if this solves your problems.
 
Upvote 0
Ok, after reading your post again, I am having trouble understadning some things. I am not understanding your work process which might be leading me to give you some incorrect solutions. When the workers are entering in the 20 bad parts, is this supposed to be one record where they can enter the 20 bad parts and reasons? Kind of like a shift summary that they would fill out at the end of the day?

Or are they really needing a seperate record for each bad part where they just duplicate most of the information?

Depending on the answer to these questions, a subform with a junction table might be what you are looking for (and you might have mentioned that originally).
 
Upvote 0
Montez659,

Thanks for sticking with this, yes a new record each time. I was thinking about this but not sure if or how to do it. I was wondering if there is a way to leave the the info in the text boxes for each record until I was complete with that transaction. For example the employee number, Item Number, Shop Order Number, Op number would stay in the text box as they entered each additional scrap qty and reason code and then when they were finished have it clear the form. So the table would look something like this.

<table border = "1" cellspacing = "0" bordercolor="#999999">
<tr><td rowspan="1" colspan="1" width="52.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>ID </b></font></td><td rowspan="1" colspan="1" width="205.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>EmployeeNumber </b></font></td><td rowspan="1" colspan="1" width="153" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>ItemNumber </b></font></td><td rowspan="1" colspan="1" width="213" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>ShopOrderNumber </b></font></td><td rowspan="1" colspan="1" width="136.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>OpNumber </b></font></td><td rowspan="1" colspan="1" width="114" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>GoodPcs </b></font></td><td rowspan="1" colspan="1" width="112.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>ScrapPcs </b></font></td><td rowspan="1" colspan="1" width="204" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>ScrapReason </b></font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>StartTime </b></font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>StopTime </b></font></td><td rowspan="1" colspan="1" width="156" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>Date </b></font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "left" valign = "bottom" bgcolor ="#4F81BD"><font color="#FFFFFF"><b>TotalTime </b></font></td></tr>
<tr><td rowspan="1" colspan="1" width="52.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">29 </font></td><td rowspan="1" colspan="1" width="205.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">8034 </font></td><td rowspan="1" colspan="1" width="153" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">31874 </font></td><td rowspan="1" colspan="1" width="213" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">58021 </font></td><td rowspan="1" colspan="1" width="136.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">55 </font></td><td rowspan="1" colspan="1" width="114" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">564 </font></td><td rowspan="1" colspan="1" width="112.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">5 </font></td><td rowspan="1" colspan="1" width="204" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">Reason 1 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">6:00 AM </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">2:30 PM </font></td><td rowspan="1" colspan="1" width="156" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">4/14/2011 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">8.5 </font></td></tr>
<tr><td rowspan="1" colspan="1" width="52.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">30 </font></td><td rowspan="1" colspan="1" width="205.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">5246 </font></td><td rowspan="1" colspan="1" width="153" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">31874 </font></td><td rowspan="1" colspan="1" width="213" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">58021 </font></td><td rowspan="1" colspan="1" width="136.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">55 </font></td><td rowspan="1" colspan="1" width="114" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="112.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">2 </font></td><td rowspan="1" colspan="1" width="204" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">Reason 2 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="156" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">4/14/2011 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td></tr>
<tr><td rowspan="1" colspan="1" width="52.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">31 </font></td><td rowspan="1" colspan="1" width="205.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">8034 </font></td><td rowspan="1" colspan="1" width="153" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">31874 </font></td><td rowspan="1" colspan="1" width="213" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">58021 </font></td><td rowspan="1" colspan="1" width="136.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">55 </font></td><td rowspan="1" colspan="1" width="114" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="112.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">2 </font></td><td rowspan="1" colspan="1" width="204" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">Reason 3 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="156" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">4/14/2011 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td></tr>
<tr><td rowspan="1" colspan="1" width="52.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">32 </font></td><td rowspan="1" colspan="1" width="205.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">8034 </font></td><td rowspan="1" colspan="1" width="153" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">31874 </font></td><td rowspan="1" colspan="1" width="213" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">58021 </font></td><td rowspan="1" colspan="1" width="136.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">55 </font></td><td rowspan="1" colspan="1" width="114" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="112.5" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">5 </font></td><td rowspan="1" colspan="1" width="204" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">Reason 4 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td><td rowspan="1" colspan="1" width="156" height="30" align = "center" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000">4/14/2011 </font></td><td rowspan="1" colspan="1" width="133.5" height="30" align = "right" valign = "bottom" bgcolor ="#FFFFFF"><font color="#000000"> </font></td></tr>
</table>
 
Upvote 0
Ok, then new record. So the code I posted should work, but you need to double check ALL of your control names and variable names because I saw a few more variations as I was looking over it again. Just so you understand the code, let me break it down a bit for you. For
Code:
varEmployeeNumber = Me!EmployeeNumber.Value
varEmployeeNumber is your variable - make sure you declare it or VBA might have a fit.
Code:
Private Sub Command46_Click()
Dim varEmployeeNumber 

a = MsgBox("Do you want to enter extra scrap codes?", vbYesNo)
If a = vbYes Then
    
    varEmployeeNumber = Me!EmployeeNumber.Value
Do this for all of your variables. The part that says Me! is refering to the form that is currently open, and after the Me! is EmployeeNumber which refers to the control. Of course, .Value is so you can pull the value. Maybe you know all this, but like I said, I saw a lot of inconsistencies in your code so I just wanted to review this. So double check and make sure all your variables are correctly spelled when you are refering to them. Make sure all of your controls are correctly spelled as well. Some of your control names and variable names had underscores in them while others didn't, which is probably the cause of your problems.

Let me know how it goes or if you need any more help.
 
Upvote 0
Thank you for the help and the explanation I will give it a try and let you know how it turns out,
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,896
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top