Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter information automatically

Status
Not open for further replies.

caykamanj1966

Technical User
Jun 23, 2013
45
0
0
US
Example below:

I have a field on a form called: johnDoe

I have another field on that form called: forJohnDoeData

I have a combo box with values, which is called "purpose"

If I select one of the values, which is: junkMan, from the combo field "purpose" I have information that automatically appears in the field:
johnDoe.

Now since there is automatic data in johnDoe, I want the field: forJohnData, to automatically put a number "1" in that field.

I have the following code to this, but since I don't physically put data in the johnDoe field, the field "forJohnData" does not show the number 1, until I physically use the pulldown to select the data.

If Me.purpose = "junkMan" Then
Me.forJohnData = "1"

End If

How do I get the forJohnData to show the number 1 when anything automatically goes into the johnDoe field.

Code:
If Me.purpose = "junkMan" Then
Me.forJohnData = "1"

End If
 
I figured it out.

I used SetFocus and that worked:)

Forms![frm_expenses].Form![purpose].SetFocus
 
I don't know if these are your actual names or you are obscuring them for some reason. I don't believe I have ever seen so much hard-coding of data values into code. I assume you are happy with your result since apparently something works.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Yeah, I am still new to this coding, but trying to learn:)

Here is what I ended up doing afterUpdate and please let me know how can it be done easier.

Code:
Private Sub companyName_AfterUpdate()

If Me.companyName = "Autozone" Then
Me.purpose = "Business Expense"
Me.to = "2141 S. Chambers Rd., Aurora, CO  80014"
Me.totalMiles = 3

End If

If Me.companyName = "O'Reilly" Then
Me.purpose = "Business Expense"
Me.to = "17090 E Quincy Ave, Aurora, CO 80015"
Me.totalMiles = 2

End If

If Me.companyName = "Fashcash Pawn" Then
Me.purpose = "Business Expense"
Me.to = "648 S Parker Rd. Unit 5. Aurora, CO 80014"
Me.totalMiles = 7

End If

If Me.companyName = "Rosie's Diner" Then
Me.purpose = "Business Expense"
Me.to = "14061 E Iliff Ave, Aurora, CO 80014"
Me.totalMiles = 4

End If

If Me.companyName = "USCCA/Delta Defense LLC" Then
Me.purpose = "Business Expense"

End If

If Me.companyName = "SiriusXM" Then
Me.purpose = "Business Expense"

End If

If Me.companyName = "Protective Life Insurance" Then
Me.purpose = "Business Expense"

End If

If Me.companyName = "Gasamat - Smoker Friendly" Then
Me.purpose = "Business Expense"
Me.to = "2698 S Parker Rd. Aurora, CO 80014"
Me.totalMiles = 4

End If

If Forms![frm_expenses].Form![purpose] = "Business Expense" Then
Forms![frm_expenses].Form![purpose].SetFocus
Me.forReport = 1

End If

If Forms![frm_expenses].Form![purpose] = "Business Lunch" Then
Forms![frm_expenses].Form![purpose].SetFocus
Me.forReport = 1

End If

If Forms![frm_expenses].Form![purpose] = "Medical" Then
Forms![frm_expenses].Form![purpose].SetFocus
Me.forReport = 1

End If

If Forms![frm_expenses].Form![purpose] = "Gas" Then
Forms![frm_expenses].Form![purpose].SetFocus
Me.forReport = 1

End If

End Sub

The companyName entries are my value from a combo box (i.e. Autozone). I keep adding to the code when I have to use another value.

Please let me know how can this be done easier brother and thank you in advance!
 
You should never have to modify code or expressions or tables or queries or reports or forms in finished applications.

I would expect you to have a table of companies with fields for the CompanyName, CompanyPurpose, CompanyAddress, CompanyMiles.

You would only store these values in a single table. In all other related tables, you would store the primary key value from the company table (I almost always use an AutoNumber for primary keys).


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
I agree with everything Duane said.
Plus, about coding:
caykamanj1966 said:
Yeah, I am still new to this coding, but trying to learn:)
Here is what I ended up doing afterUpdate and please let me know how can it be done easier.

If you have [blue]the same code / logic[/blue] in more than one place:

Code:
[blue]
If Forms![frm_expenses].Form![purpose] =[/blue] "Business Expense"[blue] Then
   Forms![frm_expenses].Form![purpose].SetFocus
   Me.forReport = 1
End If
If Forms![frm_expenses].Form![purpose] = [/blue]"Business Lunch"[blue] Then
   Forms![frm_expenses].Form![purpose].SetFocus
   Me.forReport = 1
End If
If Forms![frm_expenses].Form![purpose] = [/blue]"Medical" [blue]Then
   Forms![frm_expenses].Form![purpose].SetFocus
   Me.forReport = 1
End If
If Forms![frm_expenses].Form![purpose] = [/blue]"Gas"[blue] Then
   Forms![frm_expenses].Form![purpose].SetFocus
   Me.forReport = 1
End If[/blue]

Create a simple Sub, pass some arguments and process all of that in one place.


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top