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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

So basic it's emabarrassing 1

Status
Not open for further replies.

TeresePamela

Programmer
Sep 4, 2003
40
US
I'm new to ACCESS and becoming familiar with forms, but how do I simply read in a file, manipulate the contents of one or more fields, replace the fields with their new value and/or write to a second file and then to the next record in the first file?? This has got to be right under my nose, but I can't see it. Would I do this from a button on a form? Is there a way to run vba code from somewhere else?

I have the Access 2000 desktop devleoper's guide and the Access InsideOut. Plenty of help for forms and SQL, but for the above I can't find anything. What am I missing??

Thanks for any assistance and thanks for your patience.

Pam
 
Pam,

You need to set the record source for the form to the table or query you want and then insure that that controls have their control sources set properly as well.


Hope this helps,

Steve
 
The easiest way is to as Steve suggested set the form data control to the desired table or query. This can be done in the new form wizard if you create a form in design view, right click a blank region off of the form (the dark gray stuff) and set it in properties > data > event.

Once this is done, you can go to view > toolbox and drag a Command Button from the toolbox onto the form, which should bring up a 'Command Button Wizard'. You will see many of the things you are looking for in Record Navigation and Record Operations.

Once you create these, you can open them in Visual Basic, and at that point the sky is the limit.

Hope this helps!
Rusty

The early bird gets the worm, but the second mouse gets the cheese.
-------------------------------------
92.5% of statistics mean nothing.
 
Thanks for the input guys, The area I'm having a problem with (this is so embarassing) is the vba coding to:

Select a file, goto first record, if fieldx = abc, replace it with xyz, then read the next record and perform the same if, then, else and keep looping through until eof is reached.

I don't have any trouble creating and using the basic data-entry buttons on the form.

I'm used to doing this type of thing as a program in VFP and am a bit lost as to how(why) to do this via a form. I was thinking I'd create a blank form and just stick a button called "Run Program" on it and then put the vba code in the on-click event. Trouble is I can't figure out what the code is. I know I'm trying to start in the middle, I just can't concentrate on the form thing until I know how to do the coding part.

I really do appreciate any and all input.

Pam
 
You just want to loop through each record in a table? No form involved, just modify the data?

ChaZ

Ascii dumb question, get a dumb Ansi
 
Yes, that's all. Well do a bunch of stuff in the middle, but I'm ok with that part :)
 
Well, try some simple code like this

Function myfunction()
Set Sele1 = currentdb.openrecordset ("YourTable")
Sele1.movefirst
While not Sele1.Eof()
if this = that
Sele1.Edit
Sele1.FieldName = Blah
Sele1.Update
Sele1.movenext
Wend
end function


Ascii dumb question, get a dumb Ansi
 
Thanks Blorf,

I had trouble with it as a function (remember I don't know what I'm doing......... yet), but with a little tweak it works perfectly. This is what I now have as the click event of a button:

Private Sub Command2_Click()
Set Sele1 = CurrentDb.OpenRecordset("GI_DATA")
Sele1.MoveFirst
While Not Sele1.EOF()
If Sele1.DESCRIPT > " " Then
Sele1.Edit
Sele1.DESCRIPT = "TEST RECORD"
Sele1.Update
End If
Sele1.MoveNext
Wend
MsgBox "Sub has finished updating"
End Sub

I can't thank you enough, Hopefully one day soon I'll be contributing as well as taking.

Pam
 
No problem. Enjoy

ChaZ

Ascii dumb question, get a dumb Ansi
 
And what about a one line code, like this ?
DoCmd.RunSQL "UPDATE GI_DATA SET DESCRIPT='TEST RECORD' WHERE DESCRIPT > ' ';"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That would be far too easy.

Or not.

ChaZ

Ascii dumb question, get a dumb Ansi
 
Thanks PHV,

Blorf's solution is the best one for me as I need to do a whole bunch more with this code and it's also a learning process, I'm boring some people by repeating this I'm sure,but ... I'm coming from structured coding in dBase, Foxpro and Visual FoxPro, but know nothing about vba which is what I really need and I need it in the ACCESS environment.

Thanks anyway, the SQL example will come in useful somewhere along the way I'm sure.

Pam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top