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

help in microsoft visual basic and forms in microsoft access 2007

Status
Not open for further replies.

lefko

Programmer
Mar 4, 2008
6
GR
Hi eneryone,
i am new in programming visual basic (the last couple of days), i can get as much help as you can give me!
I have a database in Microsoft Access 2007. I display my data in a form. My problem is that when i change a value in a drop down box on the form i want to update the table with the change.
The point i really need help is how to connect to my database- i am already confused with ODBC, ADO,DAO etc- and update my table
Can enyone try to explain me what to do?
 
Set the ControlSource of the dropdown to the field you want to update.

As you are new use/play only with wizards and get a good hold on that. Later you will come to know what are these..

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Your reply is not very encouraging for me. I am new in programming vb but new in programming generaly.
i am posting you a code sample:

Private Sub thema_AfterUpdate()
Dim Mydbs As DAO.Database
Dim rstMyRS As DAO.Recordset

Set Mydbs = CurrentDb
Set rstMyRS = dbsNorthwind.OpenRecordset("eggrafes")

If (arx_thema = "blabla") Then
If (thema.Value = "blabla") Then
rsMyRS.Edit
rsMyRS!epilogi = "blabla"
rsMyRS.Update
End If
If (thema.Value = "blabla") Then
rsMyRS.Edit
rsMyRS!epilogi = "blabla"
rsMyRS.Update
End If
End If

i get an error message about another user uses the database. I think it has something to do with the connection.
 
What is dbsNorthwind ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yes you are right about dbsNorthwind that was wrong, i had the correct one in my code is actually Mydbs. i am still having problems. There is no update in my table here is the code again:
Private Sub thema_AfterUpdate()
Dim dbsNorthwind As DAO.Database
Dim rsMyRS As DAO.Recordset

Set dbsNorthwind = CurrentDb
Set rsMyRS = dbsNorthwind.OpenRecordset("eggrafes", dbOpenDynaset, uid = "admin")

If (arx_thema = "bbbb") Then
If (thema.Value = "bbbbb") Then
'this part down here is not working
rsMyRS.Edit
rsMyRS!epilogi = "bbbbb"
rsMyRS.Update
End If
If (thema.Value = "bbbb") Then
rsMyRS.Edit
rsMyRS!epilogi = "bbbb"
rsMyRS.Update
End If
End If
the code continues.....
 
To go back to ZmrAbdulla's answer, just set the control source of the drop down to the relevant field in the table. There's really no need to go messing about with VBA.

Is there a specific reason why you have to do this in code?
 
Do you have the DAO library referenced correctly? Goto VBA, then click Tools - References. Check to see if you have the latest Microsoft DAO library checked (scroll down to make sure) and be sure to place it near the top of your references or it'll never get pass the ADO library. Of course, in your post you didn't state if you're still getting a conflict error.
 
Yes there is a reason for using vba. My first goal was to display to the user certain fields of my form depending on the value of one drop down list. So i use a sub for the current form and visible true- false on some fields. The next goal was to update the database depending on the changes the user makes on that drop down.
About the messages i get: the first time i open the database and try to make a change on an existing record, i get a message about if i want to save the changes because another user is using the database. if i say yes there is no change to my data, the only field updated is only the thema value.
 
fneily, It won't be a reference problem.. if it was then the error would read "User defined function... " something like that. I have too little knowledge on Access2007

lefko,
Displaying/hiding controls also can be done in a bound form.

Here is a simple way of updating a record.
Code:
Private Sub cmdUpdate_Click()
    Dim strSQLUpdate As String
    strSQLUpdate = "UPDATE tblUsers SET tblUsers.[Password] = 'pwd'" & _
                 " WHERE (((tblUsers.UserName)='Zameer'));"
    DoCmd.RunSQL strSQLUpdate
End Sub
There are many ways to do this.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
You may try this:
Code:
...
Dim rsMyRS As DAO.Recordset
[!]Me.Dirty = False[/!]
Set dbsNorthwind = CurrentDb
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
i have tried the code you sent me ZmrAbdulla thank you very much for that. Now when i try to make a change on a record i get a confirmation message about editing if i say yes and move to the next record i get a write conflict error with 3 options (save the change, cancel change, copy to clipboard) and the message that while editing the record another user was editing it to. I am the only person using the database. How can i get rid of all these?
 
THANK YOU PHV that whas great and solved my problem!!!!!!
You are great. Can you explain me what was that?

thank you so much i was really disapointed
 
what was that
The same thing as the following:
DoCmd.RunCommand acCmdSaveRecord

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top