save textbox values to a record (1 Viewer)

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
I have an unbound form with 3 combo's to look up a record from a table and the record is displayed in a couple of textboxes.

I'd like to save the values of the textboxes to a record in another table by clicking a save button. I don't have relational tables..

Does anybody know how to do this?
I searched the forum but couldn't find the answer.
 

ajetrumpet

Banned
Local time
Today, 00:52
Joined
Jun 22, 2007
Messages
5,638
I have an unbound form with 3 combo's to look up a record from a table and the record is displayed in a couple of textboxes.

I'd like to save the values of the textboxes to a record in another table by clicking a save button.
I would think the best way would be the recordset method:
Code:
.addnew
  !newtable'sfield1 = me.textbox1
  !newtable'sfield2 = me.textbox2
.update
This of course, is only if you're adding a new record to that table. If you just want to insert those two textbox values into a record that already exists in the table, you'll have to use either the seek or findfirst method to locate the record before you update it with the code.
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
Thanks alot, I will try this :D
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
.addnew
!newtable'sfield1 = me.textbox1
!newtable'sfield2 = me.textbox2
.update

I think I need a bit more help, I'm pretty new to VB but learning..
What I have so far is:

Recordset.addnew
tblStorage!awb = me.txt_awb
Recordset.update

(tablename = tblStorage, fieldname = awb, textboxname = txt_awb)
It tells me I have no variables set? I'm pretty much clueless on how to do this..
 

ajetrumpet

Banned
Local time
Today, 00:52
Joined
Jun 22, 2007
Messages
5,638
What I have so far is:



(tablename = tblStorage, fieldname = awb, textboxname = txt_awb)
It tells me I have no variables set? I'm pretty much clueless on how to do this..
You need to declare them with the Dim statement and set them with the Set statement, like this:
Code:
Dim rs as recordset
  set rs = currentdb.openrecordset("tblStorage")

with rs
  .addnew
    !awb = me.txt_awb
  .update
end with
There is a lot of research available on the recordset method, which is what you are doing here. It is a very common practice, especially for me; I use it a lot. I do think it's redundant sometimes, but it's pretty easy to learn, and you can perform a lot of manipulation by using it.
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
You need to declare them with the Dim statement and set them with the Set statement, like this:
Code:
Dim rs as recordset
  set rs = currentdb.openrecordset("tblStorage")

with rs
  .addnew
    !awb = me.txt_awb
  .update
end with
There is a lot of research available on the recordset method, which is what you are doing here. It is a very common practice, especially for me; I use it a lot. I do think it's redundant sometimes, but it's pretty easy to learn, and you can perform a lot of manipulation by using it.

Many thanks !! :D
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
This of course, is only if you're adding a new record to that table. If you just want to insert those two textbox values into a record that already exists in the table, you'll have to use either the seek or findfirst method to locate the record before you update it with the code.
I got it all working, although now I try to figure out how to look if the value in the textbox already exists after inserting a number in the txt_awb textbox.
If I understand it right I need the Dlook method for this?
 

ajetrumpet

Banned
Local time
Today, 00:52
Joined
Jun 22, 2007
Messages
5,638
I got it all working, although now I try to figure out how to look if the value in the textbox already exists after inserting a number in the txt_awb textbox.
If I understand it right I need the Dlook method for this?
No, I wouldn't use DLookup for this. I would use the FindFirst method to check it.

I assume what you want to do is check to see weather or not the value you have entered in one of your textboxes already exists in the table that you are adding a record to. Correct?

Since you have already provided the bit of code that you want to use for the text box, here is the full conditional code that I would use (to update the box dependent upon the value, and weather or not it already exists:
Code:
Dim rs as recordset
  set rs = currentdb.openrecordset("tblStorage")

with rs

   .movelast
   .movefirst
   .findfirst ("[awb] = txt_awb")

   if .nomatch = false then
      msgbox "You already have a record assigned to this number. " & vbcr & _
         "Please enter another number to be assigned!"
   else:
      .addnew
         !awb = me.txt_awb
      .update
   end if

end with
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
Many many thanks, I'm very happy now..
I figured out the DLookup method but without succes as it's not a unique value.. Ah well, I'm learning (slowly) so it's all usefull.

I will certainly try this method this evening and let you know if it works :)
It's the very last thing I have to do to my form so again thanks!
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
.FindFirst ("[awb] = Me.txt_awb")

I get a runtime error '3251'.
Operation is not supported for this type of object.

I'm puzzled :(
 

ajetrumpet

Banned
Local time
Today, 00:52
Joined
Jun 22, 2007
Messages
5,638
I get a runtime error '3251'.
Operation is not supported for this type of object.
Script,

Try this instead:
Code:
.findfirst "[awb]='" & [txt_awb] & "'"
I found this on post #8 here. Apparently, this is yet another mix up of quotation marks. I tested the above code on one of my files and it works fine. The problem is though, the first one that I wrote also works fine. :rolleyes: :rolleyes:

If you want something to ponder over, try this:

1) My VBA books say that the method should work by writing it this way (taking the control value out of the quotation marks):
Code:
.findfirst "[awb]= " & txt_awb.(value)
2) But, the process works fine with the control value included in the quotation marks:
Code:
.findfirst "[awb]='" & [txt_awb] & "'"
Now, that's strange if you ask me!
 
Last edited:

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
Thanks :D

Maybe it's just my form, I tried to bind it before and after closing the application it was no longer possible to access the data in the database. The data was there in the table but just not accessible through my form. That's when I decided to unbound it again..

Anyway, I got it working by using the DLookUp method that shows the storage date when that value is already in the table..
It works though and I think my form is finally finished :D
 

ajetrumpet

Banned
Local time
Today, 00:52
Joined
Jun 22, 2007
Messages
5,638
Glad to hear Script. It doesn't sound like I was much help, but if I was, you're welcome! :)
 

BadScript

Registered User.
Local time
Yesterday, 22:52
Joined
Oct 30, 2007
Messages
73
I learned a bit more and your help was very much appreciated :)
 

Users who are viewing this thread

Top Bottom