Unbound and Bound textbox data transfer (1 Viewer)

Micron

AWF VIP
Local time
Today, 08:28
Joined
Oct 20, 2018
Messages
3,476
Are OpenArgs really needed?
I don't know if we looked at the same file but from what I saw, the form being referenced was closed before the code attempted to get the values from it. So I fail to see how your approach would work with that code. Maybe I missed something, but I think you did too because I suggested that already:
or open the next form and either a) retrieve the values from the first form
 

zeroaccess

Active member
Local time
Today, 07:28
Joined
Jan 30, 2020
Messages
671
I don't know if we looked at the same file but from what I saw, the form being referenced was closed before the code attempted to get the values from it. So I fail to see how your approach would work with that code. Maybe I missed something, but I think you did too because I suggested that already:
Obviously, you would set/pass values before the form closes using that method.
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Are OpenArgs really needed?

I just say Forms!frmName!somecontrol = control on selection/popup form
please the textboxes are on the same form. Even when I requested for the data transfer to fire at the activating button, an error message is returned. The unbound textbox called txtemplevel is populated using the instruction

forms!forms screen! txtemplevel=user
the same does not occur when either

forms!forms screen! txtuser=user
forms!forms screen! username=user

this is because "username" is the bound textbox of the recordset
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Hi. I looked at your files and it seems Micron already got it figured out in Post #18. Have you tried his suggestions?
Please the solution provided by Micron does not work as the two text boxes are on the same form. His recommendation was unclear. The command button vba code writes to the unbound textbox
Forms![employee info]![txtlogname] = user (populate unbound textbox with data)
Forms![employee info]![Username] = user ( gives an error message and does not populate the textbox)
The username textbox is an attribute of a table called employee

All I want is for the two text boxes to have the same data.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:28
Joined
Oct 29, 2018
Messages
21,357
Please the solution provided by Micron does not work as the two text boxes are on the same form. His recommendation was unclear. The command button vba code writes to the unbound textbox
Forms![employee info]![txtlogname] = user (populate unbound textbox with data)
Forms![employee info]![Username] = user ( gives an error message and does not populate the textbox)
The username textbox is an attribute of a table called employee

All I want is for the two text boxes to have the same data.
Hi. I'll let Micron respond to that, but what exactly is unclear with his suggestion? If you tell us which part doesn't make sense, we can try to explain it more.
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Hi. I'll let Micron respond to that, but what exactly is unclear with his suggestion? If you tell us which part doesn't make sense, we can try to explain it more.
He stated that I am working with two forms when i am only working with one form. Also, he stated that the forms closes as such the data is lost which is not true as the two events that I have used are on the form when it is active. In this case I cannot see the OpenArgs property applicable.
 

Micron

AWF VIP
Local time
Today, 08:28
Joined
Oct 20, 2018
Messages
3,476
He stated that I am working with two forms when i am only working with one form. Also, he stated that the forms closes as such the data is lost which is not true as the two events that I have used are on the form when it is active.
Here is your code without using code tags so that I can show colour:
Private Sub Command1_Click()
Dim ID As Integer
Dim level As Integer
Dim tempname As String

If IsNull(Me.txtlevel1) Or (Me.txtlevel1) = 2 Then
DoCmd.Close
DoCmd.OpenForm "login"
Else <-- so if txtlevel1 is OK, do the DLookups and assign them to (undeclared?) variables "levels" and "user"
level = DLookup("ID", "securitylevel", "[securityID]='" & Me.txtlevel1.Value & "'")
user = DLookup("[username]", "users", "[userlogin]='" & Me.txtuser1.Value & "'")
DoCmd.Close <-- now close this form because simply "close" closes the active object
EDIT- come to think of it, I cannot see the rest of this running anyway once you've invoked the close method of this form. It should be the last thing done on this form.

DoCmd.OpenForm "Employee info" <--now open another form, even though you say there is only one involved
Forms![employee info]![txtemplevel] = level <--now try make these controls equal the values for user and level, which are no longer in scope because you just closed the form they were on
Forms![employee info]![txtlogname] = user
Forms![employee info]![Username] = user

End If
End Sub
If you have declared user and level as variables somewhere else and their scope is either global or they are at the module level then you need to explain that, otherwise it looks like it is your problem. "the two events that I have used are on the form when it is active" means nothing if the scope of the variables is limited to the form you closed, or a sub that terminates even if the form remains open. You need to clear up where those variables are declared.
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Here is your code without using code tags so that I can show colour:
Private Sub Command1_Click()
Dim ID As Integer
Dim level As Integer
Dim tempname As String

If IsNull(Me.txtlevel1) Or (Me.txtlevel1) = 2 Then
DoCmd.Close
DoCmd.OpenForm "login"
Else <-- so if txtlevel1 is OK, do the DLookups and assign them to (undeclared?) variables "levels" and "user"
level = DLookup("ID", "securitylevel", "[securityID]='" & Me.txtlevel1.Value & "'")
user = DLookup("[username]", "users", "[userlogin]='" & Me.txtuser1.Value & "'")
DoCmd.Close <-- now close this form because simply "close" closes the active object
EDIT- come to think of it, I cannot see the rest of this running anyway once you've invoked the close method of this form. It should be the last thing done on this form.

DoCmd.OpenForm "Employee info" <--now open another form, even though you say there is only one involved
Forms![employee info]![txtemplevel] = level <--now try make these controls equal the values for user and level, which are no longer in scope because you just closed the form they were on
Forms![employee info]![txtlogname] = user
Forms![employee info]![Username] = user

End If
End Sub
If you have declared user and level as variables somewhere else and their scope is either global or they are at the module level then you need to explain that, otherwise it looks like it is your problem. "the two events that I have used are on the form when it is active" means nothing if the scope of the variables is limited to the form you closed, or a sub that terminates even if the form remains open. You need to clear up where those variables are declared.
No,this code works to open the employer form when the last instruction (Forms![employee info]![Username] = user) is added. The correct login username is entered into the txtlogname textbox (unbound textbox). The issue here is that, I want the content of the txtlogname textbox to also be dumped into the bound textbox, Username.
 

zeroaccess

Active member
Local time
Today, 07:28
Joined
Jan 30, 2020
Messages
671
It's simply me.txt2 = me.txt1

After Update event of txt1

But can you explain why you are recording a login name? Is it for logging purposes?
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
It's simply me.txt2 = me.txt1

After Update event of txt1

But can you explain why you are recording a login name? Is it for logging purposes?
Thanks, but this instruction gives an error message. No, it is to monitor who edits a record after it has been entered. I am working with a backend of sql-server and frontend of access. The bound textbox is in a sql-server table
 

Micron

AWF VIP
Local time
Today, 08:28
Joined
Oct 20, 2018
Messages
3,476
I'm not getting through so I will have to bow out in the hopes that someone else (who has actually looked at the posted files) manages to communicate. Maybe it's me...
Ciao.
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
I'm not getting through so I will have to bow out in the hopes that someone else (who has actually looked at the posted files) manages to communicate. Maybe it's me...
Ciao.
Thanks for the effort. It is really giving me challenge. When I do resolve it, will inform all concern
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:28
Joined
Oct 29, 2018
Messages
21,357
Thanks for the effort. It is really giving me challenge. When I do resolve it, will inform all concern
Okay, I looked back at the file you attached earlier, and remembered it was a Word document with the following image in it.

info.png


After looking at that image, I had to agree with Micron about you using two different forms. Clearly, from the image, there's a form called "Employee info" and another form called "forms screen." So, in your code, we know you are opening "Employee info," but which form are you closing? In other words, which form is your code attached?
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Okay, I looked back at the file you attached earlier, and remembered it was a Word document with the following image in it.

View attachment 80199

After looking at that image, I had to agree with Micron about you using two different forms. Clearly, from the image, there's a form called "Employee info" and another form called "forms screen." So, in your code, we know you are opening "Employee info," but which form are you closing? In other words, which form is your code attached?
The code is written for the command button on the "forms screen" to open number of forms including the "Employee info". The intention here is for whosoever opens and edit any record on the "employee form", the name should be updated into the trigger table in the SQL-Server table also called "employee info". Everything has been working as intended but for the "username textbox". The Environ ("username") would have worked but I want only the names in the "users" table to be the target group.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:28
Joined
Oct 29, 2018
Messages
21,357
The code is written for the command button on the "forms screen" to open number of forms including the "Employee info". The intention here is for whosoever opens and edit any record on the "employee form", the name should be updated into the trigger table in the SQL-Server table also called "employee info". Everything has been working as intended but for the "username textbox". The Environ ("username") would have worked but I want only the names in the "users" table to be the target group.
Hi. Just for fun, try modifying your code to this:
Code:
Private Sub Command1_Click()
Dim ID As Integer
Dim level As Integer
Dim tempname As String

If IsNull(Me.txtlevel1) Or (Me.txtlevel1) = 2 Then
    DoCmd.Close
    DoCmd.OpenForm "login"
Else
    level = DLookup("ID", "securitylevel", "[securityID]='" & Me.txtlevel1.Value & "'")
    user = DLookup("[username]", "users", "[userlogin]='" & Me.txtuser1.Value & "'")
    DoCmd.OpenForm "Employee info"
    Forms![employee info]![txtemplevel] = level
    Forms![employee info]![txtlogname] = user
    Forms![employee info]![Username] = user
    DoCmd.Close acForm, Me.Name
End If
End Sub
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Hi. Just for fun, try modifying your code to this:
Code:
Private Sub Command1_Click()
Dim ID As Integer
Dim level As Integer
Dim tempname As String

If IsNull(Me.txtlevel1) Or (Me.txtlevel1) = 2 Then
    DoCmd.Close
    DoCmd.OpenForm "login"
Else
    level = DLookup("ID", "securitylevel", "[securityID]='" & Me.txtlevel1.Value & "'")
    user = DLookup("[username]", "users", "[userlogin]='" & Me.txtuser1.Value & "'")
    DoCmd.OpenForm "Employee info"
    Forms![employee info]![txtemplevel] = level
    Forms![employee info]![txtlogname] = user
    Forms![employee info]![Username] = user
    DoCmd.Close acForm, Me.Name
End If
End Sub
1585596430101.png

Thanks as you can see the debug message is shown in yellow
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:28
Joined
Oct 29, 2018
Messages
21,357
View attachment 80337
Thanks as you can see the debug message is shown in yellow
Hi. Sorry, but no. All I see is a line highlighted in yellow - no "message" per se. What was the actual error message? It has to be, at least, different than what you were originally getting, right?
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
Hi. Sorry, but no. All I see is a line highlighted in yellow - no "message" per se. What was the actual error message? It has to be, at least, different than what you were originally getting, right?
The yellow colour over instruction in vba indicates a debug alert.
1585621129505.png

when debug button is clicked the screen I send appears
1585621434966.png

above is the screen of the sql-server table with usernam efield character size 25
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:28
Joined
Oct 29, 2018
Messages
21,357
The yellow colour over instruction in vba indicates a debug alert.
View attachment 80352
when debug button is clicked the screen I send appears
View attachment 80353
above is the screen of the sql-server table with usernam efield character size 25
So, if you limited your field size to 25, how many characters were you trying to store in them? How many characters are in the variable. The error seems to suggest it's more than 25.
 

yoffenddeh

New member
Local time
Today, 12:28
Joined
Mar 20, 2020
Messages
24
So, if you limited your field size to 25, how many characters were you trying to store in them? How many characters are in the variable. The error seems to suggest it's more than 25.
Less than 20 characters. I still do not know why it accepting the data. I have reduced the character size to eight and the same error message is received
 

Users who are viewing this thread

Top Bottom