Solved

Saving information from a form

Posted on 2004-04-16
8
299 Views
Last Modified: 2011-09-20
I have a main menu where you can choose to put in a new Party. This then opens a form named "Party", when i have entered all the information i have a button that says "Save Party", how do i save all the information?
How do i get the information?
Forms!Party.fields?

And if it exists it should prompt a box asking about overwriting, else just save all the information and then close the form and bring up a new empty "Party" form.

Im working in Mircosoft Access 2003, having a database and im inputting alot of information every day, im building a program for reservations.
0
Comment
Question by:illion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10843803
You could create a folder called PartyFiles in your apps directory and save each party to a file based on filename.For example:

' in declarations area at top of form
Dim PartyFolder As String, PartyFile As String

Private Sub Form_Load()
' make sure apps path is not a root dir
If Right$(App.Path, 1) <> "\" Then
    PartyFolder = App.Path & "\" & "PartyFiles"
Else
    PartyFolder = App.Path & "PartyFiles"
End If
' create folder for new partyfiles
If Dir$(PartyFolder, vbDirectory) = "" Then
    MkDir PartyFolder
End If
End Sub

' Save Party
Private Sub Command1_Click()
Dim ff As Integer
PartyFile = PartyFolder & Text1.Text ' where Text1 is the name of the party

' save to file
ff = FreeFile
Open PartyFile For Output As #ff
Print #ff, Text1.Text
Print #ff, Text2.Text
Print #ff, Text3.Text
Close #ff

End Sub

' retrieve party
Private Sub Command2_Click()
Dim ff As Integer, Ln As String
PartyFile = PartyFolder & Text1.Text ' where Text1 is the name of the party

' retrieve data fom file
ff = FreeFile
' open file for reading
Open PartyFile For Input As #ff
' read line 1 and put into Text1
Line Input #ff, Ln
Text1.Text = Ln
' read Line 2 and put into Text2
Line Input #ff, Ln
Text2.Text = Ln
' read Line 3 and put into Text3
Line Input #ff, Ln
Text3.Text = Ln
' close file
Close #ff

End Sub
0
 

Author Comment

by:illion
ID: 10844003
OK, but  i use a database called BB.mdb that stores all the partys in a Table called "Party".
I have the fields:

1 Party Name
2 Adults
3 Childs
4 Comments
0
 

Author Comment

by:illion
ID: 10844034
I have tried to use Text1.Text but it doesnt work, i have to use Text1.Value else i will get an error, and by the way how do i write when using "Party Name" as a name of the field?
"Party Name".Text?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:illion
ID: 10844077
Well the Text1.Text works if i use Text1.setFocus before.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10844132
Did your question state Microsoft access at first or did you add that?Im just wondering because I don't remember seeing it when I first read your question.

Im sure there is an easier way to do it from access,but in VB6 you could use something like this:

Private Sub Command1_Click()
Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
DataBase = "C:\BB.mdb"

' open Database Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
cn.CursorLocation = adUseClient
cn.Open

' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From Party", cn, adOpenKeyset, adLockOptimistic

' add new record to Table
rs.AddNew
rs.Fields("Party Name").Value = Text1.Text
rs.Fields("Adults").Value = Text2.Text
rs.Fields("Childs").Value = Text3.Text
rs.Fields("Comments").Value = Text4.Text
rs.Update

' close recordset
rs.Close
Set rs = Nothing

' close connection
cn.Close
Set cn = Nothing
End Sub

You could try putting square brackets around fields names with a space:

rs![Party Name]

0
 

Author Comment

by:illion
ID: 10844221
' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From Party Where [Party Name] = '" & Text1.Text & "'", cn, adOpenKeyset, adLockOptimistic

' add new record to Table
if rs.eof then
rs.AddNew
end if
rs.Fields("Party Name").Value = Text1.Text
rs.Fields("Adults").Value = Text2.Text
rs.Fields("Childs").Value = Text3.Text
rs.Fields("Comments").Value = Text4.Text
rs.Update

is this possible if record exists?
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 75 total points
ID: 10844276
You could try checking the recordcount.If it is 0,then addnew otherwise just update the current record.

Set rs = New ADODB.Recordset
rs.Open "Select * From Party Where [Party Name]='" & Text1.Text & "'", cn, adOpenKeyset, adLockOptimistic

If rs.Recordcount = 0 Then
    rs.AddNew
End If

rs.Fields("Party Name").Value = Text1.Text
rs.Fields("Adults").Value = Text2.Text
rs.Fields("Childs").Value = Text3.Text
rs.Fields("Comments").Value = Text4.Text
rs.Update
0
 

Author Comment

by:illion
ID: 10844336
Thanks for your help, now i can get starting building this thing, 25 extra for the extra effort.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question