• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1325
  • Last Modified:

MS ACCESS Autofilled Text box to Table

Hello,

Currently I have a textbox that autofills based on a combo box. When I save the form, all of the records are captured into  tabe, except for the field that is auto filled. How can I save the autofill field in the table?

Thanks,
Dustin
0
dplowman
Asked:
dplowman
  • 8
  • 5
  • 5
  • +1
1 Solution
 
jambraunCommented:
Hi Dustin,

I'd have to see your code but do you include explicit statement to capture the text of the autofilled box?  It may be as simple as you forgot the name of the box (hopefully!)

Also, can you "step in to" the code on submission and see what the values are as you progress?

Here's a sample of what I've done in the past with a training database:

 
Private Sub TrainingSubmitButton_Click()

On Error GoTo UhOh

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim UID As String
Dim TID As String
Dim Training As String
Dim DC As Date
Dim Notes As String
Dim rev As String
Dim EmpName As String
Dim DocNum As String
Dim Trainer As String

    UID = UIDSubmit
    TID = TrainingSubmit
    Training = TrainingTitleSubmit
    DC = DateSubmit
    Notes = NotesSubmit
    rev = revSubmit
    EmpName = Me.EmployeeName
    DocNum = Me.document
    Trainer = Me.Trainer

DoCmd.OpenQuery ("set most recent training flags in tracker - update query")

    Set db = CurrentDb
    Set rst = db.OpenRecordset("Training Tracker", dbOpenDynaset)

    rst.AddNew
    rst![University ID] = UID
    rst![Employee Name] = EmpName
    rst![Training ID] = TID
    rst![Training] = Training
    rst![Date Completed] = DC
    rst![Notes] = Notes
    rst![Revision] = rev
    rst![Doc Number] = DocNum
    rst![Trained By] = Trainer
    rst.Update
    rst.Close

    db.Close
    Me!TrainingSubmit = ""
    Me!DateSubmit = ""
    Me!NotesSubmit = "N/A"

DoCmd.OpenQuery ("Trainings not in compliance - update query")
[Training Compliance].Form.Requery
[Training Needed].Form.Requery
Form.Refresh
Exit Sub

UhOh:
MsgBox ("Please ensure that you have selected a training and a date before pressing submit")
Exit Sub

End Sub

Open in new window

0
 
dplowmanAuthor Commented:
Thanks for the quick response. I have little, to no experience in vba. All I have done is typed the below expression in the control source for the text box. The text box is being autofilled based on the selection the user selects in the Associate field. The asociate field, cboAssocaite, is a combo box that a query is bound to, that reports the associate and their corresponding team lead. so I can simply autofill the teamlead based on the second column. My problem is that the autofill does not link back to the table.

=[cboAssociate].[column](1)
0
 
jambraunCommented:
Nope, it doesn't ;)  Sorry, it doesn't work that way.  What I've done with this in the past is used labels instead of text boxes with NO intention of storing the information.  Maybe I can persuade you to not store this extra info?

If it's already look-upable then you really don't have a reason to store it twice (data redundancy).  It won't appear in the table but when viewing the form it will be visible.  The only reason to store data is because you need a static record that will definiately vary over time.  

VBa is a pretty nice skill to have with regard to Microsoft Access.  I had to train myself in it using web tutorials and examples.  It paid off in spades.  I'm thinking you need a submit button that will mimic somewhat that's in the code snippet above to do what you're asking; that will look at the text in the box and apply the values in to the table.  Still, since it is queryable, work with queries and reports instead of tables!  Then you don't have to store it directly in the table.  
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
dplowmanAuthor Commented:
The reason I want to store the date, the Team Lead, in this example is because our associates get assigned to different team leads quite often. So if I update the associate table with the new team lead, then the historic data would be overwritten since it is not store anywhere.

I agree that I need to learn vb. I taught myself sql and ssrs, vb is next on the list!
0
 
jambraunCommented:
Ok.  I'm trying to find the path of least resistance for you here....

How does your form make the connection between associates and the team lead now?  Also, how many team leads do you have?

The autofill is what's getting in your way here since that info doesn't post.  If you don't have too many team leads, can you populate the contents of the combo box with the query and force the user to make a selection from the list?  
0
 
jambraunCommented:
It may help to post an image of the form if you can.
0
 
Richard DanekeCommented:
Set the control of the calculated field control to a name in your table.  It is saying:  
ThisField (field name) is =[cboAssociate].[column](1)
If you don't have a field to store it in the table, add a field to the table before you rename the calculated field control.

This work could be done in Visual Basic, but it is not necessary for this call.
0
 
jambraunCommented:
Hope you're right DoDahD.  If so, I completely appologize for steering you in the wrong direction.  This is a hell of a lot easier than a VB code up.
0
 
daz84Commented:
Why have a separate text box? Why can you not simply have the combobox in place with it's control source equal to the name of the field you want the data saved in and the row source can stay as it is, being the list of associates or whatever it is. When the record is saved, the field will take the value of the combobox. I see no reason to have a separate textbox for this purpose
0
 
Richard DanekeCommented:
The question is how to save the data and not whether to save the data.  
For example, as you move to Access Web Services, you may find the calculated value here easier to work with in a SharePoint list.  Then, of course, you have Calculated fields availabe in AC2010 to address this as an option.
0
 
dplowmanAuthor Commented:
So I created a combobox with the control source as the field I would like the team lead to be saved. The rowsource = =[cboAssociate].[column](1), which is dependent on which associate is selected from the associate combobox. When I select the associate, no team lead is listed in the drop down. When I click on the drop down for the team lead field, I get "the record source =[cboAssociate].[column](1) does not exist.



0
 
dplowmanAuthor Commented:
By dumb luck, I figured this out. I had to create two macros to capture the team lead and update it back to the table.


Private Sub cboAssociate_AfterUpdate()

Me.TEAM_LEAD = Me.cboAssociate.Column(1)

End Sub

Private Sub txtTeamLead_AfterUpdate()
Call cboAssociate_AfterUpdate
End Sub
0
 
daz84Commented:
I can see what cboAssociate is doing, that is your combox with rowsource as your list of associates (is the team leader chosen from a list of these associates?) but I don't see what TEAM_LEAD is or why you still have txtTeamLead in place

If you remove txtTeamLead and set the control source of cboAssociate to the team lead field in the table you will find that the selected item in the combox automatically update the field when the record is saved
0
 
dplowmanAuthor Commented:
I am creating a form for Team Leads to enter quality violations for their Associates. Team_Lead is the name of the field in the talbe. So when a user selects an associate from the dropdown on the form, the correct Team Lead is automatically autofilled and updated to the quality violations table.
0
 
daz84Commented:
I see, I had misunderstood. I thought the team lead was a member of the list of associates. Now that I know that is not the case this becomes a different question.

Controls:
name = txtTeamLead
type = text box
controlsource = TEAM_LEAD
value = ""

name = cboAssociate
type = combo box
row source = query1
bound column = 1
limit to list = yes

Where query1 is a query which returns 2 columns, with the list of associates in the first column and the team lead associated with that associate in the second column, you will only see the first column (the associate) when you select the combobox but the team lead will be there as the second column (index 1, since the associate will be index 0)

The only code you will need is one event procedure thus:

Private Sub cboAssociate_AfterUpdate()
txtTeamLead.value = cboAssociate.Column(1)
End Sub

You can have the text box event in there also which I see you have implemented to prevent changes, you could always just lock the text box in design time then unlock it and lock it before and after the change in runtime

txtTeamLead.locked = false
txtTeamLead.value = cboAssociate.Column(1)
txtTeamLead.locked = true

preventing the user from altering the value of txtTeamLead on your form, but allowing the change to be made in the code, saves the need to have another procedure and is a little neater.
0
 
dplowmanAuthor Commented:
Nice work daz that is exactly what I was looking for. Now that I understand this I have another situation that is quit similar.

I have one table titled qv_categories,  with fields code, section, category, subcategory (which can be null). If a user selects a section (either Compliance or Procedural) I would like the corresponding categories available from a drop down. Then when that category is selected to list the available subcategories. Attached is what the table looks like.  
QV-Categories.xlsx
0
 
daz84Commented:
I've just looked at your spreadsheet and in response to your second question, I reckon this page should answer your question.

If you need a further explination just ask, but I think the page covers the topic pretty well, and almost exactly fits your issue

http://blogs.office.com/b/microsoft-excel/archive/2009/11/24/create-conditional-drop-down-lists.aspx
0
 
dplowmanAuthor Commented:
Daz,

Maybe I didn't explain what I needed exactly. The attached spreadsheet has been imported into access as a table called qv_categories. I created a form that a user must select which section between compliance or procedural, then the next field "category" would be prefilled in a combobox with categories tied to the section chosed. The same would go for the subcategory. All three sections should be recorded on the qv_category table.

Thanks,
Dustin
0
 
daz84Commented:
Hi Dustin,

The effect you are looking for could be quite easily achieved by altering the rowsource property of the comboxes within the after_update event of the previous combox. This could be cascaded to any number of columns and as long as the control source of the comboxes is matching the field names of the qv_category table the records will update appropriately without any further interaction.

As much as I hate to be seen as cheeky, I would appreciate the points for answering your initial question with an answer you seem to be very satisfied with. This is a completely separate question. If you could post it up as a separate question I would be quite happy to write an example for you to use.

Daz
0
 
dplowmanAuthor Commented:
Sure thing! That was my first post, so I was unclear of the protocol! I will post up a new thread as well.

However, I agree with your reply, but how can I limit the section to only one compliance and one procedural option. In the excel spreadsheet there are multiple sections listed as compliance and procedural with different categories.

Thanks again for all your help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 5
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now