Prompt for LastName

G

Guest

Right now I have a form to enter an employee's family. To make it easier on
the user, when they open the form they are prompted for the employee ID whose
family they are entering. The number they input is then set as the default in
the EmployeeID textbox. The code for this is below. I have tried to modify
the code so when the user opens the form they will also be prompted to enter
the employee's last name and that last name will be set as the default in the
LastName textbox. Unfortunately I'm not that great with code. Any help would
be appreciated!
Code:
Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean

Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If

End Sub

Thanks,
Tandy
 
G

Guest

You can use the same code you already have, and change it to be used for the
family name

Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean
' You have this code
'================================================
Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If
'=================================================
' New code
'=================================================
Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee family name!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If

End Sub
 
G

Guest

Hi Ofer! I tried what you suggested and then opened the form. I enter 1001
for the Employee ID and Smith for the Last Name and it told me I had entered
an invalid last name. The reason I didn't think the exact same code would
work is because of the "IsNumeric" and such. But I don't really know anything
about code so let me know what you think.

Thanks for your help,
Tandy

Ofer said:
You can use the same code you already have, and change it to be used for the
family name

Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean
' You have this code
'================================================
Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If
'=================================================
' New code
'=================================================
Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee family name!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If

End Sub

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Tandy said:
Right now I have a form to enter an employee's family. To make it easier on
the user, when they open the form they are prompted for the employee ID whose
family they are entering. The number they input is then set as the default in
the EmployeeID textbox. The code for this is below. I have tried to modify
the code so when the user opens the form they will also be prompted to enter
the employee's last name and that last name will be set as the default in the
LastName textbox. Unfortunately I'm not that great with code. Any help would
be appreciated!
Code:
Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean

Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If

End Sub

Thanks,
Tandy
 
G

Guest

You right, I should have noticed that
Try this for the new code

Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")

If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If


--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Tandy said:
Hi Ofer! I tried what you suggested and then opened the form. I enter 1001
for the Employee ID and Smith for the Last Name and it told me I had entered
an invalid last name. The reason I didn't think the exact same code would
work is because of the "IsNumeric" and such. But I don't really know anything
about code so let me know what you think.

Thanks for your help,
Tandy

Ofer said:
You can use the same code you already have, and change it to be used for the
family name

Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean
' You have this code
'================================================
Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If
'=================================================
' New code
'=================================================
Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee family name!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If

End Sub

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Tandy said:
Right now I have a form to enter an employee's family. To make it easier on
the user, when they open the form they are prompted for the employee ID whose
family they are entering. The number they input is then set as the default in
the EmployeeID textbox. The code for this is below. I have tried to modify
the code so when the user opens the form they will also be prompted to enter
the employee's last name and that last name will be set as the default in the
LastName textbox. Unfortunately I'm not that great with code. Any help would
be appreciated!
Code:
Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean

Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If

End Sub

Thanks,
Tandy
 
G

Guest

Sorry, you can drop the Do

strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If


Tandy said:
Hi Ofer! I tried what you suggested and then opened the form. I enter 1001
for the Employee ID and Smith for the Last Name and it told me I had entered
an invalid last name. The reason I didn't think the exact same code would
work is because of the "IsNumeric" and such. But I don't really know anything
about code so let me know what you think.

Thanks for your help,
Tandy

Ofer said:
You can use the same code you already have, and change it to be used for the
family name

Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean
' You have this code
'================================================
Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If
'=================================================
' New code
'=================================================
Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee family name!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me![Enter here EmployeeFamilyFieldName].DefaultValue = strDefault
End If

End Sub

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Tandy said:
Right now I have a form to enter an employee's family. To make it easier on
the user, when they open the form they are prompted for the employee ID whose
family they are entering. The number they input is then set as the default in
the EmployeeID textbox. The code for this is below. I have tried to modify
the code so when the user opens the form they will also be prompted to enter
the employee's last name and that last name will be set as the default in the
LastName textbox. Unfortunately I'm not that great with code. Any help would
be appreciated!
Code:
Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean

Do
strDefault = InputBox("Enter the employee ID of the employee whose
family information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If

End Sub

Thanks,
Tandy
 
G

Guest

Hi Ofer! Here is the code I ended up using:

Private Sub Form_Open(Cancel As Integer)
Dim strDefault As String
Dim fGotDefault As Boolean

Do
strDefault = InputBox("Enter the employee ID of the employee whose family
information you would like to enter:")
If Len(strDefault) = 0 Then
fGotDefault = True
Else
If IsNumeric(strDefault) Then
fGotDefault = True
Else
MsgBox "That's not a valid employee ID!"
End If
End If
Loop Until fGotDefault

If Len(strDefault) > 0 Then
Me!EmployeeID.DefaultValue = strDefault
End If

Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) > 0 Then
Me![LastName].DefaultValue = strDefault
End If
Loop Until fGotDefault

End Sub

Both prompts come up and allow me to enter info. However, when the form
opens the LastName textbox, the one I want the family name to be entered into
shows this: "#Name?" Any suggestions?

Thank you so much for your help,
Tandy
 
G

Guest

You can remove the Do from the second part, and add a quote for the parameter

'Do
strDefault = InputBox("Enter the employee family of the employee whose
family information you would like to enter:")
If Len(strDefault) > 0 Then
Me![LastName].DefaultValue = "'" & strDefault & "'"
End If
'Loop Until fGotDefault
 
G

Guest

Hey Ofer! That's perfect! Thank you so much for your help! I really
appreciate it!

Thanks again,
Tandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top